2

我正在尝试为 Apple 和 Alphabet 的股票收益创建汇总统计数据。我已经有了包含所有信息的 excel 文件和下面的(小)代码:

import pandas as pd
Data = pd.read_excel('Exercise1_DataPython.xlsx')
example_series = Data.describe()
print (example_series)

但是,当我运行它时,它会返回“count、unique、top 和 freq”而不是“mean、min、max 等”。有人可以解释我如何解决这个问题吗?以及如何仅获得一个特定列的平均值、最小值、最大值等?

谢谢!

4

1 回答 1

2

使用include参数:

df = pd.DataFrame({ 'object': ['a', 'b', 'c'],
                     'numeric': [1, 2, 3],
                     'categorical': pd.Categorical(['d','e','f'])
                  })

df.describe(include='all')

输出:

        categorical  numeric object
count            3      3.0      3
unique           3      NaN      3
top              f      NaN      c
freq             1      NaN      1
mean           NaN      2.0    NaN
std            NaN      1.0    NaN
min            NaN      1.0    NaN
25%            NaN      1.5    NaN
50%            NaN      2.0    NaN
75%            NaN      2.5    NaN
max            NaN      3.0    NaN
于 2018-04-25T17:12:01.543 回答