尝试替换空值时发生Keyerror

问题描述

当我尝试替换列中的空值时,我得到了这种新的键错误类型(对我来说是新的)。

df['GarageYrBlt'] = df['GarageYrBlt'].map(lambda x: df.loc[x,'YearBuilt'] if df.loc[x,'GarageYrBlt'].isnull() else df.loc[x,'GarageYrBlt'])

我正在尝试使用lambda函数将空值映射到另一列中的值,否则告诉该函数让该值成为正值。

我收到此关键错误。

KeyError: 2003.0

During handling of the above exception,another exception occurred:
...
KeyError: 2003

然后我尝试将lambda函数更改为此

df['GarageYrBlt'].map(lambda x: replace(df.loc[x,'YearBuilt'],NaN) if df.loc[x,'GarageYrBlt'])

与以前的状态相同。请指出我做错了什么以及如何做得更好。谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...