Pandas SettingWithCopyWarning:试图在 DataFrame 的切片副本上设置值 [英] Pandas SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
本文介绍了Pandas SettingWithCopyWarning:试图在 DataFrame 的切片副本上设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在以下情况下不断收到该主题的警告:
I keep getting the warning in the subject in the following situations:
df.rename(columns={'one':'one_a'}, inplace=True)
df.rename(columns={'one':'one_a'}, inplace=True)
df.drop(['one', 'two', 'three'], axis=1, inplace=True)
df.drop(['one', 'two', 'three'], axis=1, inplace=True)
我该如何解决?
推荐答案
最简单的修复(可能也是良好的编程实践)是不进行就地操作,例如
Easiest fix (and probably good programming practice) would be to not do inplace operations, e.g.
df2 = df.rename(columns={'one':'one_a'})
这篇关于Pandas SettingWithCopyWarning:试图在 DataFrame 的切片副本上设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文