SettingWithCopyWarning Python3

59 Views Asked by At

I am finding the max of df2 by row, and setting the max value to new col on df1.

df1['max'] = df2[df2.keys().tolist()].max(axis=1)

This line is throwing a SettingWithCopyWarning. Not sure how to re-write it to make the warning go away. How to re-write it?

1

There are 1 best solutions below

0
On

The warning typically is a result of chained assignments and you can read more about it in this answer and this blog post also goes into great detail.

If you wish to turn it off, you can use:

pd.options.mode.chained_assignment = None