我对这个警告感到绝望。我正在做以下事情:groups = df.groupby('year')2018_group = groups.get_group('2018')if not 2018_group['Descripcion'].empty: desc = 2018_group.loc[2018_group['Descripcion'].notnull(), 'Desc'].copy() 2018_group.loc[:, 'Descripcion'] = desc.unique()[0] print 2018_group获取已知错误:SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrameSee the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy 2018_group.loc['Desc'] = desc.unique()[0]我想要做的是用该列中的非空值填充列“Desc”
1 回答

凤凰求蛊
TA贡献1825条经验 获得超4个赞
问题出现在您的代码中:2018_group
代表数据帧的一部分。
所以在修改之前复制切片:
2018_group = groups.get_group('2018').copy()
顺便说一句,你copy
在你的定义中desc
没有明显的目的。
添加回答
举报
0/150
提交
取消