0

How do I multiply a column by a scalar in pandas version 1.4.1 and replace the old column without tripping SettingWithCopyWarning. Could not find answer that worked for this version of pandas.

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: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df.loc[:, "Fixed Rate 1"] *= (10**4)
cpage
  • 119
  • 6
  • 27
  • It depends on where the object `df` came from. Your operation `df.loc[:, "Fixed Rate 1"] *= (10**4)` doesn't necessarily raises the copy warning in every pandas object. How was the dataframe created? From another one? – Filippe O. Gonçalves Feb 18 '22 at 03:11
  • If you [search the warning](https://stackoverflow.com/search?q=SettingWithCopyWarning), you would see a whole bunch of related questions. – Quang Hoang Feb 18 '22 at 03:16

0 Answers0