matplotlib框架中的熊猫直方图,带有日期重采样

问题描述 投票:1回答:1

我创建了一个包含每小时数据和三列的数据框。它看起来像:

                           A       B            C
2017-01-01 00:00:00  14417.5900  15252.8700  15252.8700
2017-01-01 01:00:00   1754.4800  14639.5600  14639.5600
2017-01-01 02:00:00     64.2600     14.7900     14.7900
2017-01-01 03:00:00     50.5789    486.8810    486.8810
2017-01-01 04:00:00      7.2784      8.6431      8.6431
2017-01-01 05:00:00    444.1068     28.7847     28.7847

我想创建一个柱状图直方图,其中按月比例比较模型A,B和C。因此,我将数据汇总为:

df = df.resample('M').sum() 

此时,我被卡住了。我已经尝试过两个熊猫功能,例如

df = df.resample('M').sum().hist()

但是我得到三个不同的数字。另外,我想转到可以个性化输出的matplotlib框架。

欢迎提出任何建议。

真的非常感谢

python pandas date matplotlib histogram
1个回答
0
投票

我认为您想要DataFrame.plotDataFrame.plot

kind = 'bar'

df.resample('M').sum().plot(kind = 'bar')

DataFrame.plot.bar

DataFrame.plot.bar

我们也可以使用:

df.resample('M').sum().plot.bar()

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.