1

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)
Rom M
  • 129
  • 14

1 Answers1

2

This warning is just letting you know that you may be modifying a copy of a df and not the original. In my experience, it's often a false positive. If you find this to be the case for you as well, you can turn off the warning.

For more information, see this post, and especially the links @Garrett provided.

Community
  • 1
  • 1
aonophoenix
  • 36
  • 1
  • 3