Skip to main content
 首页 » 编程设计

python之描述 Python Pandas 模块中的函数

2024年09月07日7lautakyan007

我正在尝试为股票创建汇总统计信息 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 等”。有人可以向我解释如何解决这个问题吗?我怎样才能得到一个特定列的平均值、最小值、最大值等?

谢谢!

请您参考如下方法:

使用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