熊猫系列 SettingWithCopyWarning 以下警告

我对这个警告感到绝望。我正在做以下事情:


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 DataFrame


See 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”


紫衣仙女
浏览 144回答 1
1回答

凤凰求蛊

问题出现在您的代码中:2018_group代表数据帧的一部分。所以在修改之前复制切片:2018_group = groups.get_group('2018').copy()顺便说一句,你copy在你的定义中desc没有明显的目的。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python