为了账号安全,请及时绑定邮箱和手机立即绑定

数据帧上的python loc问题

数据帧上的python loc问题

一只萌萌小番薯 2021-11-23 16:46:44
我目前正在使用 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'



查看完整回答
反对 回复 2021-11-23
?
蓝山帝景

TA贡献1843条经验 获得超7个赞

好吧,就像@roganjosh 说我把 () 而不是 [],但我现在有同样的警告“SettingWithCopyWarning,我已经收到了这个警告并使用了 .copy(),但是有没有更好的方法呢?


查看完整回答
反对 回复 2021-11-23
  • 2 回答
  • 0 关注
  • 158 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信