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

posted @ 2019-11-25 00:16  武功震树  阅读(1319)  评论(0编辑  收藏  举报