0

We are making a formula in python however, run against the setting with copy warning.

We have tried different .copy() and .loc options but the warning always appears again when we completely re-run the code.

df_no_missing.loc[:,'Turnover'] = (df_no_missing['Quantity'] * df_no_missing['PricePerPiece'])

df_no_missing.head()

We expect the column with the turnover without a warning. We do get the desired output however we would like to get the output without the following warning:

SettingWithCopyWarning: 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 See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy self.obj[key] = _infer_fill_value(value) /Users/noortjetaal/anaconda3/lib/python3.7/site-packages/pandas/core/indexing.py:543: SettingWithCopyWarning: 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 See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy self.obj[item] = s
Paritosh Singh
  • 6,034
  • 2
  • 14
  • 33
  • Possible duplicate of [How to deal with SettingWithCopyWarning in Pandas?](https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas) – Paritosh Singh Jul 25 '19 at 09:43
  • Tried the solutions in that article but didn't work.. – Lisanne Peeters Jul 26 '19 at 11:24
  • The first answer points out that it may be a false positive, which is actually the case here since you explicitly assign the result back into the df. The answer also explains why it's needed. Tl;dr it's a false positive. – Paritosh Singh Jul 26 '19 at 12:08

0 Answers0