pandas DataFrame 警告(SettingWithCopyWarning)

两盒软妹~` 提交于 2019-12-05 12:35:49

报警:

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!