Reputation: 79
I have a Panda Dataframe prices with the following structure:
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]
I would like to get a plot similar to the one below with hours on y-axis from the Period column, dates on the x-axis from the Period column, and the corresponding color on the graph set by the value in the FCR-N column.
I haven't figured out how to obtain such a plot. What would be the best way to do it?
Upvotes: 2
Views: 240
Reputation: 863791
Use DataFrame.pivot_table
with some aggregation funecion, e.g. sum
and then seaborn.heatmap
:
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)
Upvotes: 1