【发布时间】:2018-01-14 06:55:30
【问题描述】:
我收到此错误:
C:\Users\rt\Anaconda3\lib\site-packages\pandas\core\indexing.py:337: 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
self.obj[key] = _infer_fill_value(value)
C:\Users\rt\Anaconda3\lib\site-packages\pandas\core\indexing.py:517: 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
self.obj[item] = s
但是,我已经在使用 .loc,所以不确定为什么会发生此错误。代码大纲是这样的:
for name, group in results.groupby():
for idx, row in group.iterrows():
group.loc[idx, 'area'] = 10.0
我正在使用最新的 pandas (0.20.3) 和 python (3.6)
【问题讨论】:
-
你能添加结果df吗?