如何在pandas groupby中输出大量直方图 [英] How to output a large number of histograms in a pandas groupby
问题描述
df
是带有天列的数据框.有一百天我想查看每100天数据列的直方图.问题在于此代码在单个图表上输出所有内容,并且所有直方图都堆叠在一起.两个问题:
df
is a dataframe with a days column. There are 100 days. I want to look at a histogram for my data column for each of the 100 days. The problem is that this code outputs everything on a single chart and all histograms are stacked together. Two questions:
- 是否有建议每天获取一张直方图?
- 是否有任何建议将每个直方图保存到适当命名的文件中?
注意:当我在下面的代码中将hist
替换为describe
时,完全可以给我100个描述序列.另外,grouper.get_group(days)
对象的类型是pandas.series
.
Note: When I replace hist
in my code below with describe
, it perfectly gives me 100 describe series. Also, the type of the grouper.get_group(days)
object is pandas.series
.
我的简单代码:
grouper = df.groupby('days')['data']
for days in grouper.groups.keys():
print grouper.get_group(days).hist()
推荐答案
一种选择是在ipython qtconsole
或ipython notebook
中使用内联绘图:
One option would be to use inline plotting either in ipython qtconsole
or ipython notebook
:
%matplotlib inline
import matplotlib.pyplot as plt
for days in grouper.groups.keys():
grouper.get_group(days).hist()
plt.show()
这篇关于如何在pandas groupby中输出大量直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!