明白吗df.isnull.mean()在python中

2024-09-28 03:13:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个数据帧数据框。代码就是这样写的

df.isnull().mean().sort_values(ascending = False)

这是部分输出-

inq_fi                                 1.0
sec_app_fico_range_low                 1.0

我想知道它是怎么工作的?在

如果我们使用,df.isnull()它将为每个单元格返回True或False。mean()将如何给我们正确的输出。我的目标是找出所有列中空值的百分比。以上输出表示inq_fi和sec_app_fico_range_low具有所有缺失值。在

我们也不是按sort\u值传递的吗?在


Tags: 数据代码falseappdfrangesecmean
1条回答
网友
1楼 · 发布于 2024-09-28 03:13:47

分解如下:

df.isnull()
#Mask all values that are NaN as True
df.isnull().mean()
#compute the mean of Boolean mask (True evaluates as 1 and False as 0)
df.isnull().mean().sort_values(ascending = False)
#sort the resulting series by column names descending

也就是说,一个有价值的专栏:

^{pr2}$

评估为:

[True, False, False, False]

解释为:

[1, 0, 0, 0]

导致:

0.25

相关问题 更多 >

    热门问题