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']]
详见: