【问题标题】:Good way to view/print descriptive statisctics of a large data set in python?在 python 中查看/打印大型数据集的描述性统计数据的好方法?
【发布时间】:2017-05-18 13:05:03
【问题描述】:

我有相当大的数据集(67 列,9800 行)。我想检查描述性统计数据。以下是我目前所做的:

import pandas as pd
df = pd.DataFrame(np.random.randn(5, 3), index=['a', 'c', 'e', 'f', 'h'], columns=['one', 'two', 'three'])
print(df.describe())
print(df.isnull().sum())

我正在尝试获取基本的描述性统计数据和 NaN 计数。但是,鉴于数据集很大,所有印刷品都被删减了。

什么是在不获得节略报告的情况下进行展示的明智方式? 如何将生成的表格导出到 Excel? 熊猫是要走的路吗?

【问题讨论】:

    标签: python-3.x pandas statistics export


    【解决方案1】:

    我认为您可以使用loc 添加带有NaN 统计信息的新行:

    df1 = df.describe()
    df1.loc['isnull'] = df.isnull().sum()
    print (df1)
                 one       two     three
    count   5.000000  5.000000  5.000000
    mean    0.237377 -0.346928 -0.322925
    std     0.890415  0.883372  0.603782
    min    -1.293332 -1.317518 -0.936159
    25%     0.415596 -1.043694 -0.730677
    50%     0.503251 -0.318196 -0.348271
    75%     0.520425  0.053760 -0.228624
    max     1.040943  0.891006  0.629104
    isnull  0.000000  0.000000  0.000000
    

    然后使用DataFrame.to_excel:

    df1.to_excel('file.xlsx')
    

    【讨论】:

    • 谢谢!但印刷品仍被删减。此外,print(df.count()) 仅显示非 NaN,但不显示其他统计数据(均值、计数、q1 等)。
    【解决方案2】:
    df.describe().append(df.isnull().sum().rename('isnull'))
    
                 one       two     three
    count   5.000000  5.000000  5.000000
    mean    0.003423 -0.121164  0.386899
    std     0.532280  0.749847  0.614877
    min    -0.596886 -0.767480 -0.621084
    25%    -0.254336 -0.641685  0.258331
    50%    -0.022049 -0.587911  0.657703
    75%     0.048015  0.631354  0.693988
    max     0.842374  0.759903  0.945556
    isnull  0.000000  0.000000  0.000000
    

    to_excel导出

    df.describe().append(df.isnull().sum().rename('isnull')).to_excel(filename)
    

    【讨论】:

    • 酷!这是一种优雅的方式!我也可以导出表格吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 2021-09-08
    • 2022-08-21
    • 1970-01-01
    • 1970-01-01
    • 2019-06-25
    相关资源
    最近更新 更多