TypeError:“value”参数必须是标量、dict或Series,但您在Python中传递了一个“DataFrame”

2024-05-15 21:08:38 发布

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

目前我正在讨论主题问题。我不知道它为什么会破裂,需要做哪些修改。在

代码:

table = df.pivot_table(values='LoanAmount', index='Self_Employed' ,columns='Education', aggfunc=np.median)

def fage(x):
    return table.loc[x['Self_Employed'],x['Education']]

#Replacing missing values

df['LoanAmount'].fillna(df[df['LoanAmount'].isnull()].apply(fage,axis=1),inplace =True) 

输出:

[15]:df['LoanAmount'].fillna(df['LoanAmount'].isnull()].apply(fage,axis=1),inplace=True)

回溯(最近一次呼叫):

^{pr2}$

Tags: selftruedf主题tableapplyvalueseducation
1条回答
网友
1楼 · 发布于 2024-05-15 21:08:38

嗨,请确保

我希望您之前没有执行这行来填充LoanAmount的缺失值

df['LoanAmount'].fillna(df['LoanAmount'].mean(), inplace=True)

错误是LoanAmount已经用其他值填充,并且中没有缺少值所以呢它抛出错误。在

替换缺少的值:

^{pr2}$

在执行上述代码之前,请确保LoanAmount中缺少值execute below命令以进行检查。在

df.apply(lambda x: sum(x.isnull()),axis=0)

上面的命令将显示LoanAmount的缺失计数。如果缺少值,则只能用fage或mean替换。在

相关问题 更多 >