gpt4 book ai didi

python - matplotlib 框架中的 pandas 直方图,具有日期重采样功能

转载 作者:太空宇宙 更新时间:2023-11-03 19:47:11 26 4
gpt4 key购买 nike

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

                           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() 

此时我陷入了困境。我已经尝试过 pandas 的两个功能,例如

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

但是我得到了三个不同的数字。此外,我想转向 matplotlib 框架,在那里我可以个性化输出。

欢迎任何建议。

真的非常感谢

最佳答案

我想你想要DataFrame.plotkind = 'bar':

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

DataFrame.plot.bar

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

enter image description here

我们还可以使用:

df.groupby([df.index.month,df.index.year]).sum().plot.bar()

enter image description here

关于python - matplotlib 框架中的 pandas 直方图,具有日期重采样功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60055590/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com