0

I'm trying to set some values in one column (col_2) coming from another column (col_3) when values in col_1 fulfill a condition. I'm doing that with the .loc operator as after all my research looking for alternatives it looks as the best practice.

data.loc[data.col_1.isin(['A','B']),col_2]=data[col_3]

Nevertheless this stills trigger the 'SettingWithCopyWarning:'.

Is there any other way to do this operation without raising that warning?

user2082695
  • 250
  • 3
  • 14
  • 1
    This is most likely because your `data` variable is a subset of another dataframe (e.g. you created `data` with some type of `data = some_df.loc[...]`. You can use `data = data.copy()` before you try to change the values in `data` to remedy this warning though. – Cameron Riddell Oct 13 '20 at 08:55

1 Answers1

0

Following the advice of Cameron,the line of code was part of a function, where data was passed as argument.

Starting the function with data = data.copy() solves the issue

user2082695
  • 250
  • 3
  • 14