在python中替换我的数据帧中的NA

2024-10-01 22:35:48 发布

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

我已经调用了我想用NAs替换的train和test数据帧的特性索引:

Catlist1=['FireplaceQu','BsmtQual','BsmtExpo','BsmtCond','BsmtFinType1','GarageFinish',
'GarageType','GarageCond','GarageQual','MasVnrType']
Catlist2=['FireplaceQu','BsmtQual','BsmtExpo','BsmtCond','BsmtFinType1','GarageFinish',
'GarageType','GarageCond','GarageQual','MasVnrType']

要替换我调用的NAs:

for i in Catlist1:
   train_df.ix[pd.isnull(train_df[:,i]),i]=np.nanmedian(train_df.ix[:,i])
for i in Catlist2:
   test_df.ix[pd.isnull(test_df[:,i]),i]=np.nanmedian(test_df.ix[:,i])

我收到了错误信息:

TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

我不确定我是否理解此错误消息以及我可能在这里做错了什么。谢谢您!你知道吗


Tags: thetestdffortrainixnasgaragefinish

热门问题