如何在数据框架中绘制缺失值的分布

发布于 2025-01-25 23:34:07 字数 785 浏览 2 评论 0原文

我有一个带有100列的数据框架,想通过绘制图来研究缺失值的比例。

我能够使用以下代码:

代码:

missing_data_in_df=pd.DataFrame({'NaN_Counts': df.isna().sum(), 'NaN_Proportions(%)': (df.isna().sum() / df.shape[0]) * 100}).sort_values(by='NaN_Counts', ascending=False)
missing_data_in_df.head()

输出:

        NaN_Counts  NaN_Proportions(%)
Col1    889061      99.757636
Col2    685843      76.955435
Col3    584612      65.596749
Col4    476524      53.468668
Col4    392318      44.020282

尝试使用直方图可视化 -

代码:

missing_data_in_df.hist()

获取

我将输出AS -https ://i.sstatic.net/7yndt 。 png“ rel =” nofollow noreferrer“> ”

是否有任何方法可以获取任何方法X轴的数据框?

I have a data frame with 100's of column and would like to investigate the proportion of missing values by plotting graph.

I'm able to get the proportion using below code :

Code :

missing_data_in_df=pd.DataFrame({'NaN_Counts': df.isna().sum(), 'NaN_Proportions(%)': (df.isna().sum() / df.shape[0]) * 100}).sort_values(by='NaN_Counts', ascending=False)
missing_data_in_df.head()

Output :

        NaN_Counts  NaN_Proportions(%)
Col1    889061      99.757636
Col2    685843      76.955435
Col3    584612      65.596749
Col4    476524      53.468668
Col4    392318      44.020282

Now when trying to visualize using histogram -

Code :

missing_data_in_df.hist()

I'm getting output as -

enter image description here

Is there any way to get feature names of dataframe in x-axis ?

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

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

发布评论

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

评论(1

小糖芽 2025-02-01 23:34:07

使用您的dataFrame:

import pandas as pd

df = pd.DataFrame(
    {
        "features": ["Col1", "Col2", "Col3", "Col4", "Col5"],
        "NaN_Counts": [889061, 685843, 584612, 476524, 392318],
        "NaN_Proportions(%)": [99.757636, 76.955435, 65.596749, 53.468668, 44.020282],
    }
)

这是一种方法:

df.plot.bar(x="features", subplots=True)

ouput:

With your dataframe:

import pandas as pd

df = pd.DataFrame(
    {
        "features": ["Col1", "Col2", "Col3", "Col4", "Col5"],
        "NaN_Counts": [889061, 685843, 584612, 476524, 392318],
        "NaN_Proportions(%)": [99.757636, 76.955435, 65.596749, 53.468668, 44.020282],
    }
)

Here is one way to do it:

df.plot.bar(x="features", subplots=True)

Ouput:

enter image description here

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