0

I have a relatively simple line of code that I have used before that has never shown an error.

It reads

df["total_assets"] = df[["asset_A", "asset_N", "asset_K", "asset_MU"]].sum(axis=1, numeric_only=True)

but I'm getting the following error


C:\conda\envs\py39\lib\site-packages\pandas\core\frame.py:3607: 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
  self._set_item(key, value)

which is resulting in the total asset columns just equalling the assets_MU column.

Is there an obvious cause for this and/or is there another easy way to sum columns based on column headers?

Any help is much appreciated, thanks.

Monish Khatri
  • 820
  • 1
  • 7
  • 24
spcol
  • 437
  • 4
  • 15

0 Answers0