完整的警告为:
C:\Users\moxia\Anaconda3\lib\site-packages\pandas\core\indexing.py:189: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
self._setitem_with_indexer(indexer, value)
这是我使用
df['row2'].loc['index1'] = 1
时的报错。
也就是说pandas 不建议这样去修改值
此时我们使用
df['row2'].at['index1'] = 1
不在收到警告!
还有的是分组之后操作也会收到这个警告 此时我们做浅copy就可以解决
for key, group in df.groupby(by='column1'):
df_group = group.copy()