Reputation: 69
df['Action']=np.nan
for i in range(len(df)-1):
if df['Close Price'][i] < df['Close Price'][i+1]:
df['Action'][i] = 1
elif df['Close Price'][i] >= df['Close Price'][i+1]:
df['Action'][i] = -1
df = df.dropna()
df
Upvotes: 0
Views: 291
Reputation: 82
this is not the correct way
df['Close Price'][i] < df['Close Price'][i+1]
:
of getting ith row value of a specific column in pandas
do
if df['Close Price'].iloc[i]< df['Close Price'].iloc[i+1] :
Upvotes: 1