pandas DataFrame 警告(SettingWithCopyWarning)

Posted sxinfo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pandas DataFrame 警告(SettingWithCopyWarning)相关的知识,希望对你有一定的参考价值。

报警:

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

简单述之:

A为一个dataframe,

B = A[[‘a‘, ‘b‘]]
B[‘a‘] = B[‘a‘] + 1

将会有上面的警告,提示最后一行有问题,但实际上应该修改上一行,为:
B = A.loc[:,[‘a‘,‘b‘]]

详见:

https://www.cnblogs.com/pig-fly/p/7875472.html

以上是关于pandas DataFrame 警告(SettingWithCopyWarning)的主要内容,如果未能解决你的问题,请参考以下文章

pandas DataFrame 警告(SettingWithCopyWarning)

DataFrame 性能警告

pandas 报警告:A value is trying to be set on a copy of a slice from a DataFrame

pandas警告:SettingWithCopyWarning

当列是现有列的布尔测试时,为啥向 Pandas DataFrame 添加列会返回 SettingWithCopy 警告?

Python Pandas 绘图警告