I have a data frame that I divide into 2 subsets based on the values of one column (positive or negative).
Let's say one columns contains the following values:
1
4
9
2
1
I basically want to create a column in each subset computing the difference between the one value and the one just before.So it would give here something like this:
n/a
3
5
-7
-1
Then I just want to shift the value one row above. I used the code below that in the end gives me the result but I always get this warning that I don't understand. "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" Can you please help?
df_left = df_s[df_s['Benchmark Sigma'] < 0]
df_right = df_s[df_s['Benchmark Sigma'] > 0]
df_left['Benchmark Sigma Interval'] = (df_left['Benchmark Sigma']-df_left['Benchmark Sigma'].shift(1))
df_right['Benchmark Sigma Interval'] = (df_right['Benchmark Sigma']-df_right['Benchmark Sigma'].shift(1))
df_left['Benchmark Sigma Interval']=df_left['Benchmark Sigma Interval'].shift(-1)
df_right['Benchmark Sigma Interval']=df_right['Benchmark Sigma Interval'].shift(-1)