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) / len(df.index))
print(round(percent,2))
输入是https://query.data.world/s/Hfu_PsEuD1Z_yJHmGaxWTxvkz7W_b0
输出应该是
Ord_id 0.00
Prod_id 0.00
Ship_id 0.00
Cust_id 0.00
Sales 0.24
Discount 0.65
Order_Quantity 0.65
Profit 0.65
Shipping_Cost 0.65
Product_Base_Margin 1.30
dtype: float64
要覆盖所有缺失的值并舍入结果:
输出:
更新让我们将
mean
与isnull
一起使用:输出:
IIUC:
输出:
这个怎么样?我想我以前在这里发现过类似的东西,但现在我看不到了。。。
如果您希望对缺少的百分比进行排序,请按照上面的操作:
如注释中所述,您也可以只使用上面代码中的第一行,即:
相关问题 更多 >
编程相关推荐