简体   繁体   English

为什么缺失值没有填充?

[英]Why the missing values aren't filled?

While using the pandas filling method on a data frame I am using median values of that specific column to fill the values, instead of filling it is being doubled.在数据框上使用熊猫填充方法时,我使用该特定列的中值来填充值,而不是填充它被加倍。 Here's the missing values before :这是之前的缺失值:

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

Hence I used the following to fill the Na values:因此,我使用以下内容来填充 Na 值:

train['application_underwriting_score'] = train['application_underwriting_score'].fillna(train['application_underwriting_score'].median(),inplace=True)

But instead of getting filled I am getting more Na values:但我没有得到填满,而是得到了更多的 Na 值:

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

I already checked the median, which is coming out to be 92.1.我已经检查了中位数,结果是 92.1。 What could be the possible fault in my code?我的代码中可能有什么错误?

You need remove inplace=True :您需要删除inplace=True

train['application_underwriting_score'] = train['application_underwriting_score'].fillna(train['application_underwriting_score'].median())

Or:或者:

train['application_underwriting_score'].fillna(train['application_underwriting_score'].median(), inplace=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM