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

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

    Update let's use mean with isnull:

    df.isnull().mean() * 100
    

    Output:

    Ord_id                 0.000000
    Prod_id                0.000000
    Ship_id                0.000000
    Cust_id                0.000000
    Sales                  0.238124
    Discount               0.654840
    Order_Quantity         0.654840
    Profit                 0.654840
    Shipping_Cost          0.654840
    Product_Base_Margin    1.297774
    dtype: float64
    

    IIUC:

    df.isnull().sum() / df.shape[0] * 100.00
    

    Output:

    Ord_id                 0.000000
    Prod_id                0.000000
    Ship_id                0.000000
    Cust_id                0.000000
    Sales                  0.238124
    Discount               0.654840
    Order_Quantity         0.654840
    Profit                 0.654840
    Shipping_Cost          0.654840
    Product_Base_Margin    1.297774
    dtype: float64
    

提交回复
热议问题