I am beginner to pandas and out of a DataFrame i want to join another - The code is runable but the shape of the joind DataFrame is only on row. What can i do? Target is, to join both df Frames, the other data completly joined to DataFrame
Actually - the dict i want to join has the shape 3 x 1, so the joined Dict Returns NaN Fields.
What did i wrong?
Here is my Code:
import pandas_datareader.data as pdr
import fix_yahoo_finance
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
df = pdr.get_data_yahoo("AMZ", start="2019-01-01", end="2019-02-28")
def supeperc(df):
#Date = pd.Series(df.index.values)
high = pd.Series(df['High'])
low = pd.Series(df['Low'])
close = pd.Series(df['Close'])
open = pd.Series(df['Open'])
gesamtR = high - low
diffhighcopen = abs(high - open)
diffhighclose = abs(high - close)
difflowcopen = abs(low - open)
difflowclose = abs(low - close)
diffopenclose = pd.Series(abs(open - close))
calccandle = pd.Series(0)
if np.where(open < close):
if np.where((diffopenclose * 100 / gesamtR) > 70):
calccandle = pd.Series(2)
elif np.where((diffhighcopen * 100 / gesamtR) < 15):
calccandle = pd.Series(2)
pass
else:
calccandle = pd.Series(1)
elif close < open:
if np.where((diffopenclose * 100 / gesamtR) > 70):
calccandle = pd.Series(-2)
elif np.where((difflowclose * 100 / gesamtR) < 15):
#sollte eigentlich ein Hammer sein
#print (difflowclose * 100 / gesamtR)
calccandle = pd.Series(-2)
else:
calccandle = pd.Series(-1)
pass
else:
if np.where(((difflowcopen + difflowclose) / 2 * 100 / gesamtR) <= 2):
calccandle = pd.Series(-3)
elif np.where(((diffhighcopen + diffhighclose) / 2 * 100 / gesamtR) <= 2):
calccandle = pd.Series(+3)
else:
calccandle = pd.Series(0)
if np.where((gesamtR * 100 / open) > 5):
myrange= pd.Series(1)
else:
myrange= pd.Series(0)
if np.where((diffopenclose * 100 / open) > 5):
myChange= pd.Series(1)
else:
myChange= pd.Series(0)
can = {'FakeCandle':calccandle,'ProzentVola':myrange,'Aend':myChange}
print (myChange)
dfCand = pd.DataFrame(can)
#print (dfCand)
df = df.join(dfCand)
return df
print (supeperc(df))