JavaScript
x
5
1
import pandas as pd
2
df = pd.read_csv('https://query.data.world/s/Hfu_PsEuD1Z_yJHmGaxWTxvkz7W_b0')
3
percent= 100*(len(df.loc[:,df.isnull().sum(axis=0)>=1 ].index) / len(df.index))
4
print(round(percent,2))
5
input is https://query.data.world/s/Hfu_PsEuD1Z_yJHmGaxWTxvkz7W_b0
and the output should be
JavaScript
1
12
12
1
Ord_id 0.00
2
Prod_id 0.00
3
Ship_id 0.00
4
Cust_id 0.00
5
Sales 0.24
6
Discount 0.65
7
Order_Quantity 0.65
8
Profit 0.65
9
Shipping_Cost 0.65
10
Product_Base_Margin 1.30
11
dtype: float64
12
Advertisement
Answer
How about this? I think I actually found something similar on here once before, but I’m not seeing it now…
JavaScript
1
4
1
percent_missing = df.isnull().sum() * 100 / len(df)
2
missing_value_df = pd.DataFrame({'column_name': df.columns,
3
'percent_missing': percent_missing})
4
And if you want the missing percentages sorted, follow the above with:
JavaScript
1
2
1
missing_value_df.sort_values('percent_missing', inplace=True)
2
As mentioned in the comments, you may also be able to get by with just the first line in my code above, i.e.:
JavaScript
1
2
1
percent_missing = df.isnull().sum() * 100 / len(df)
2