如何在pandas groupby中输出大量直方图 [英] How to output a large number of histograms in a pandas groupby

查看:149
本文介绍了如何在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:

  1. 是否有建议每天获取一张直方图?
  2. 是否有任何建议将每个直方图保存到适当命名的文件中?

注意:当我在下面的代码中将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 qtconsoleipython 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆