I've been struggling with a Pandas warning for a while now.
I have this pretty simple piece of code:
def get_delta(df):
df['delta_current_day'] = df['close'] - df['open']
df = df[pd.notnull(df['delta_current_day'])]
df['delta_next_day'] = df['delta_current_day'].shift(-1)
return df
Every time I get this error:
A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead
I've read a lot of question about it here on stackoverflow but none works for me. I've tried somethings like this:
df.loc[:, 'delta_next_day'] = df['delta_current_day'].shift(-1)
# OR
list = df['delta_current_day'].tolist()
df.loc[:, 'delta_next_day'] = list[:1]
but I still get the same error.
What am I doing wrong?