Python:根据小时和日期绘制值
我有一个具有以下结构的熊猫数据帧价格:Python:根据小时和日期绘制值,python,pandas,Python,Pandas,我有一个具有以下结构的熊猫数据帧价格: prices Out[28]: FCR-N FCR-D Period 2016-01-01 00:00:00 28.949 5.285 2016-01-01 01:00:00 28.820 5.314 2016-01-01 02:00:00 28.734 5.330 2016-01-01 03:00:00 28.822 5.2
prices
Out[28]:
FCR-N FCR-D
Period
2016-01-01 00:00:00 28.949 5.285
2016-01-01 01:00:00 28.820 5.314
2016-01-01 02:00:00 28.734 5.330
2016-01-01 03:00:00 28.822 5.292
2016-01-01 04:00:00 28.822 5.251
... ...
2020-04-30 19:00:00 8.767 11.587
2020-04-30 20:00:00 8.441 6.528
2020-04-30 21:00:00 7.857 8.275
2020-04-30 22:00:00 7.873 7.896
2020-04-30 23:00:00 7.893 8.046
[37967 rows x 2 columns]
我想得到一个类似于下面的图,从Period列得到y轴上的小时数,从Period列得到x轴上的日期,以及由FCR-N列中的值设置的图形上的相应颜色
我还没有弄明白如何获得这样的阴谋。最好的方法是什么
与一些聚合功能一起使用,例如,sum
,然后:
看起来像热图?你可以用seaborn。
import seaborn as sns
df1 = df.pivot_table(index=df.index.hour,
columns=df.index.year,
values='FCR-N',
fill_value=0,
aggfunc='sum')
print (df1)
Period 2016 2020
Period
0 28.949 0.000
1 28.820 0.000
2 28.734 0.000
3 28.822 0.000
4 28.822 0.000
19 0.000 8.767
20 0.000 8.441
21 0.000 7.857
22 0.000 7.873
23 0.000 7.893
sns.heatmap(df1)