我目前正在使用 jupyter notebook 开发一个关于 python 的项目。我想预测法国体育场的上座率(联赛 1)。为了实现这一点,我用漂亮的汤从网上获取了数据。我现在正在尝试清理我的数据:我有一些体育场馆的缺失值,我想为特定球队(Olympique lyonnais)分配体育场馆。我第一次尝试:stats_match.stade[(stats_match.saison >= 2017) & (stats_match.domicile == 'Olympique Lyonnais') & (stats_match.stade.isna())] = 'Groupama stadium'这给了我那个错误:SettingWithCopyWarning:试图在 DataFrame 的切片副本上设置值所以我按照说明进行了尝试:stats_match.stade.loc((stats_match.saison >= 2017) & (stats_match.domicile == 'Olympique Lyonnais') & (stats_match.stade.isna())) = 'Groupama stadium'这给了我:文件“”,第 3 行 stats_match.stade = stats_match.stade.loc((stats_match.saison >= 2017) & (stats_match.domicile == 'Olympique Lyonnais') & (stats_match.domicile.isna())) = 'Groupama体育场'语法错误:无法分配给函数调用我在这里想念什么?我必须使用 .where 函数吗?非常感谢
2 回答

FFIVE
TA贡献1797条经验 获得超6个赞
这应该是正确的;
stats_match.loc[(stats_match.saison >= 2017) & (stats_match.domicile == 'Olympique Lyonnais') & (stats_match.stade.isna())] = 'Groupama stadium'

蓝山帝景
TA贡献1843条经验 获得超7个赞
好吧,就像@roganjosh 说我把 () 而不是 [],但我现在有同样的警告“SettingWithCopyWarning,我已经收到了这个警告并使用了 .copy(),但是有没有更好的方法呢?
添加回答
举报
0/150
提交
取消