Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:根据小时和日期绘制值_Python_Pandas - Fatal编程技术网

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)