pandas :固定宽度的直方图 [英] Pandas : histogram with fixed width

查看:137
本文介绍了 pandas :固定宽度的直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些想要做直方图的数据,但是我希望直方图从给定的值开始并且条的宽度是固定的.例如,对于系列[1、3、5、10、12、20、21、25],我要代替

I have data which I want to do an histogram, but I want the histogram to start from a given value and the width of a bar to be fixed. For example, for the serie [1, 3, 5, 10, 12, 20, 21, 25], I want, instead of

>>> p.Series([1, 3, 5, 10, 12, 20, 21, 25]).hist(bins=3).figure

#  |       |
#  |   |   |
#  |   |   |
#  0   8.5 17

我希望这些条的宽度为10:

I want the bars to have a width of 10 :

|       |
|   |   |
|   |   |
0   10  20

我该怎么做?

我最终得到了想要的

推荐答案

我认为

p.Series([1, 3, 5, 10, 12, 20, 21, 25]).hist(bins=[0, 10, 20, 30]).figure

将做您想要的.或者,您可以做

will do what you want. Alternately you can do

p.Series([1, 3, 5, 10, 12, 20, 21, 25]).hist(bins=3, range=(0,30)).figure

有关hist的信息,请参见文档. np.histogram的href ="http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html" rel ="noreferrer">文档.

See documentation for hist and the documentation for np.histogram.

我怀疑您也遇到了一些问题,因为它标记了容器的中心,而不是边缘.

I suspect you are also running into some issues because it is labeling the center of the bins, not the edges.

这篇关于 pandas :固定宽度的直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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