Python用mean填充缺少的值,请帮助我尝试此代码,但出现错误

2024-06-18 13:14:47 发布

您现在位置:Python中文网/ 问答频道 /正文

df.loc[(data['Perkotaan'].isnull()==True),'Perkotaan']=df['Perkotaan'].mean()
df.loc[(data['Perdesaan'].isnull()==True),'Perdesaan']=df['Perdesaan'].mean()

KeyError回溯(最近一次呼叫最后一次) /get_loc中的usr/local/lib/python3.7/dist-packages/pandas/core/index/base.py(self、key、method、tolerance) 2897尝试: -&燃气轮机;2898自动返回引擎。获取锁定(铸造键) 2899除KeyError作为错误外:

pandas/_libs/index.pyx在pandas中。_libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx在pandas中。_libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi在pandas._libs.hashtable.PyObjectHashTable.get_item()中

pandas/_libs/hashtable_class_helper.pxi在pandas._libs.hashtable.PyObjectHashTable.get_item()中

KeyError:“Perkotaan”

上述异常是以下异常的直接原因:

KeyError回溯(最近一次呼叫最后一次) 2帧 /get_loc中的usr/local/lib/python3.7/dist-packages/pandas/core/index/base.py(self、key、method、tolerance) 2898自动返回引擎。获取锁定(铸造键) 2899除KeyError作为错误外: -&燃气轮机;2900从err升起钥匙错误(钥匙) 2901 2902如果公差不是无:

KeyError:“Perkotaan”


Tags: truepandasdfdatagetindex错误mean
1条回答
网友
1楼 · 发布于 2024-06-18 13:14:47

您的数据帧分配给df还是数据

df.loc[(数据['Perkotan'].isnull()==True),'Perkotan']=df['Perkotan'].mean()

我认为您必须将其更改为df或重新检查您选择的列。 “Perkotaan”不是数据帧的一列

相关问题 更多 >