修改来自Python Pandas的输出描述 [英] Modify output from Python Pandas describe
问题描述
是否可以忽略熊猫描述的某些输出? 该命令为我提供了所需的表输出(simpleDate的executeTime的计数和均值)
Is there a way to omit some of the output from the pandas describe? This command gives me exactly what I want with a table output (count and mean of executeTime's by a simpleDate)
df.groupby('simpleDate').executeTime.describe().unstack(1)
但是,我想要的只是这些,数数和均值.我要删除std,min,max等.到目前为止,我只读了如何修改列大小.
However that's all I want, count and mean. I want to drop std, min, max, etc... So far I've only read how to modify column size.
我猜测答案将是重新编写该行,而不是使用describe,但是我没有通过simpleDate 进行任何分组,并且 executeTime.
I'm guessing the answer is going to be to re-write the line, not using describe, but I haven't had any luck grouping by simpleDate and getting the count with a mean on executeTime.
我可以按日期计数:
df.groupby(['simpleDate']).size()
或按日期执行时间:
df.groupby(['simpleDate']).mean()['executeTime'].reset_index()
但是无法弄清楚组合它们的语法.
But can't figure out the syntax to combine them.
我想要的输出:
count mean
09-10-2013 8 20.523
09-11-2013 4 21.112
09-12-2013 3 18.531
... .. ...
推荐答案
Describe返回一个序列,因此您只需选择所需的对象即可
Describe returns a series, so you can just select out what you want
In [6]: s = Series(np.random.rand(10))
In [7]: s
Out[7]:
0 0.302041
1 0.353838
2 0.421416
3 0.174497
4 0.600932
5 0.871461
6 0.116874
7 0.233738
8 0.859147
9 0.145515
dtype: float64
In [8]: s.describe()
Out[8]:
count 10.000000
mean 0.407946
std 0.280562
min 0.116874
25% 0.189307
50% 0.327940
75% 0.556053
max 0.871461
dtype: float64
In [9]: s.describe()[['count','mean']]
Out[9]:
count 10.000000
mean 0.407946
dtype: float64
这篇关于修改来自Python Pandas的输出描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!