Python 为什么缺少的值不是';你没填吗?
在数据帧上使用熊猫填充方法时,我使用该特定列的中值填充值,而不是将填充值加倍。 以下是之前缺少的值:Python 为什么缺少的值不是';你没填吗?,python,pandas,dataframe,Python,Pandas,Dataframe,在数据帧上使用熊猫填充方法时,我使用该特定列的中值填充值,而不是将填充值加倍。 以下是之前缺少的值: id 0 perc_premium_paid_by_cash_credit 0 age_in_days 0 Income 0 Count_3-6_months_late
id 0
perc_premium_paid_by_cash_credit 0
age_in_days 0
Income 0
Count_3-6_months_late 0
Count_6-12_months_late 0
Count_more_than_12_months_late 0
application_underwriting_score 2974
no_of_premiums_paid 0
sourcing_channel 0
residence_area_type 0
target 0
dtype: int64
因此,我使用以下方法填充Na值:
train['application_underwriting_score'] = train['application_underwriting_score'].fillna(train['application_underwriting_score'].median(),inplace=True)
id 0
perc_premium_paid_by_cash_credit 0
age_in_days 0
Income 0
Count_3-6_months_late 0
Count_6-12_months_late 0
Count_more_than_12_months_late 0
application_underwriting_score 79853
no_of_premiums_paid 0
sourcing_channel 0
residence_area_type 0
target 0
dtype: int64
但我没有得到满足,而是得到了更多的Na值:
train['application_underwriting_score'] = train['application_underwriting_score'].fillna(train['application_underwriting_score'].median(),inplace=True)
id 0
perc_premium_paid_by_cash_credit 0
age_in_days 0
Income 0
Count_3-6_months_late 0
Count_6-12_months_late 0
Count_more_than_12_months_late 0
application_underwriting_score 79853
no_of_premiums_paid 0
sourcing_channel 0
residence_area_type 0
target 0
dtype: int64
我已经检查了中位数,结果是92.1。我的代码中可能有什么错误?您需要删除
inplace=True
:
train['application_underwriting_score'] = train['application_underwriting_score'].fillna(train['application_underwriting_score'].median())
或:
它并没有解决问题,但以下问题确实解决了:值=训练[‘申请承保评分’]。fillna(训练[‘申请承保评分’)。中位数())训练[‘申请承保评分’]=值为什么使用另一个变量来存储返回值有帮助?@KUSHAGRAVIJAYKINJAWADEKAR-我认为您需要删除
inplace=True
如果要返回或删除,请编辑答案。