Find out the percentage of missing values in each column in the given dataset

前端 未结 11 1124
逝去的感伤
逝去的感伤 2021-01-31 08:38
import pandas as pd
df = pd.read_csv(\'https://query.data.world/s/Hfu_PsEuD1Z_yJHmGaxWTxvkz7W_b0\')
percent= 100*(len(df.loc[:,df.isnull().sum(axis=0)>=1 ].index) / l         


        
11条回答
  •  日久生厌
    2021-01-31 09:29

    How about this? I think I actually found something similar on here once before, but I'm not seeing it now...

    percent_missing = df.isnull().sum() * 100 / len(df)
    missing_value_df = pd.DataFrame({'column_name': df.columns,
                                     'percent_missing': percent_missing})
    

    And if you want the missing percentages sorted, follow the above with:

    missing_value_df.sort_values('percent_missing', inplace=True)
    

    As mentioned in the comments, you may also be able to get by with just the first line in my code above, i.e.:

    percent_missing = df.isnull().sum() * 100 / len(df)
    

提交回复
热议问题