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

前端 未结 11 1121
逝去的感伤
逝去的感伤 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:31

    By this following code, you can get the corresponding percentage values from every columns. Just switch the name train_data with df, in case of yours.

    Input:

    In [1]:
    
    all_data_na = (train_data.isnull().sum() / len(train_data)) * 100
    all_data_na = all_data_na.drop(all_data_na[all_data_na == 0].index).sort_values(ascending=False)[:30]
    missing_data = pd.DataFrame({'Missing Ratio' :all_data_na})
    missing_data.head(20)
    

    Output :

    Out[1]: 
                                    Missing Ratio
     left_eyebrow_outer_end_x       68.435239
     left_eyebrow_outer_end_y       68.435239
     right_eyebrow_outer_end_y      68.279189
     right_eyebrow_outer_end_x      68.279189
     left_eye_outer_corner_x        67.839410
     left_eye_outer_corner_y        67.839410
     right_eye_inner_corner_x       67.825223
     right_eye_inner_corner_y       67.825223
     right_eye_outer_corner_x       67.825223
     right_eye_outer_corner_y       67.825223
     mouth_left_corner_y            67.811037
     mouth_left_corner_x            67.811037
     left_eyebrow_inner_end_x       67.796851
     left_eyebrow_inner_end_y       67.796851
     right_eyebrow_inner_end_y      67.796851
     mouth_right_corner_x           67.796851
     mouth_right_corner_y           67.796851
     right_eyebrow_inner_end_x      67.796851
     left_eye_inner_corner_x        67.782664
     left_eye_inner_corner_y        67.782664
    

提交回复
热议问题