如何在数据框的每一行中检查缺失值

发布于 2025-01-25 11:07:59 字数 178 浏览 1 评论 0原文

我有一个带有100列和数百万行的数据框架,并想检查每个数据框架中的丢失值。

代码:

df.isna().sum()

目前,我正在使用上述代码进行分析,这可以帮助我每列中缺少值。 我们如何获得每行缺失值WRT。

同样,[行]列的分布图[缺失值的数量]。

I have a dataframe with 100's of columns and millions of rows and would like to check the missing values in each row of dataframe.

Code :

df.isna().sum()

Currently, i'm analzing with above code which helps me with missing values in each column.
How we can get the missing values w.r.t each row.

Also, distribution plot of [column of rows] vs [number of missing values].

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨洒年华 2025-02-01 11:07:59

我们如何获得缺少值WRT WRT。

您可以在列上尝试sum

df.isna().sum(axis=1)

[行] vs [缺失值的数量]的分布图。

如果您是指每个列中缺少值的数量,则df.isna()。sum()已经给出结果。

How we can get the missing values w.r.t each row.

You can try sum on columns

df.isna().sum(axis=1)

distribution plot of [column of rows] vs [number of missing values].

If you mean number of missing values in each columns, df.isna().sum() already gives the result.

走过海棠暮 2025-02-01 11:07:59

您可以在第一次尝试以下操作:

df_nan=pd.DataFrame(df.isna().mean().reset_index()).rename(columns={"index": "columns", 0: "nan_pourcentage"}).sort_values(by='nan_pourcentage',ascending=False)

只要您就可以了解哪些列的NAN最多,并且可以绘制它,

您可以使用:df.isna知道数据帧中NAN的%总数().mean()。均值()

,现在如果您想要每行Nan的%:

for index in range(len(df.index)) :
    print("Nan in row ", index , " : " ,  df.iloc[index].isna().mean())

而不是使用打印,您可以将结果存储在数据框架中

You can try in a first time to do :

df_nan=pd.DataFrame(df.isna().mean().reset_index()).rename(columns={"index": "columns", 0: "nan_pourcentage"}).sort_values(by='nan_pourcentage',ascending=False)

Just so you can you understand which columns has the most or the less NaN, and you can plot it

You can know the % total of Nan in your dataframe using : df.isna().mean().mean()

And now if you want the % of NaN per line :

for index in range(len(df.index)) :
    print("Nan in row ", index , " : " ,  df.iloc[index].isna().mean())

Instead of using a print you can store the result in a dataframe

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文