简体   繁体   English

熊猫dropna无法正常工作

[英]Pandas dropna not working as expected

I have a dataframe and I used dropna() on it successfully as shown: 我有一个数据框,并在其上成功使用了dropna(),如下所示:

proc_train.isnull().any()

id                                  False
perc_premium_paid_by_cash_credit    False
age_in_days                         False
Income                              False
Count_3-6_months_late               False
Count_6-12_months_late              False
Count_more_than_12_months_late      False
application_underwriting_score      False
no_of_premiums_paid                 False
premium                             False
renewal                             False
sourcing_channel_B                  False
sourcing_channel_C                  False
sourcing_channel_D                  False
sourcing_channel_E                  False
Urban/Rural                         False
prem_to_inc_ratio                   False
late36_612                          False
late36_12more                       False
late612_12more                      False
perc_times_prem                     False

Then I try to take a selection of the data to use as input variables: 然后,我尝试选择要用作输入变量的数据:

X_train = proc_train.loc[:, proc_train.columns != 'renewal']
X_train = X.loc[:, X.columns != 'id']

but it then gives all the null values back: 但是它随后将所有空值都返回:

X_train.isnull().any()

perc_premium_paid_by_cash_credit    False
age_in_days                         False
Income                              False
Count_3-6_months_late                True
Count_6-12_months_late               True
Count_more_than_12_months_late       True
application_underwriting_score       True
no_of_premiums_paid                 False
premium                             False
sourcing_channel_B                  False
sourcing_channel_C                  False
sourcing_channel_D                  False
sourcing_channel_E                  False
Urban/Rural                         False
prem_to_inc_ratio                   False
late36_612                           True
late36_12more                        True
late612_12more                       True
perc_times_prem                     False

Why does this happen and what would be a better way to run this? 为什么会发生这种情况?有什么更好的方法来运行呢?

This section: 这个部分:

X_train = X.loc[:, X.columns != 'id']

should be 应该

X_train = X_train.loc[:, X_train.columns != 'id']

which produces the same all-False result for isnull().any() as before. 它将为isnull()。any()产生与以前相同的全False结果。

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

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