I have a data frame (df) with columns named date, Year, Month, Day, Hour and Energy. It is multiyear Time Series which I want to convert into a averaged single year time series with (8760 points i.e 365 * 24 points) where the column Energy_Mean is averaged out value.
df is
date Year Month Day Hour Energy
1/1/1999 0:00 1999 Jan 1 1 45.0
1/1/1999 1:00 1999 Jan 1 2 73.5
1/1/1999 2:00 1999 Jan 1 3 82.4
1/1/1999 3:00 1999 Jan 1 4 90.0
1/1/1999 4:00 1999 Jan 1 5 72.2
.
.
.
12/31/1999 23:00 1999 Dec 12 24 77.0
.
.
.
12/31/2019 23:00 2019 Dec 12 24 84.3
Task is to convert it into an averaged form as shown below:
Month Day Hour Energy_Mean
Jan 1 1 22.45
Jan 1 2 73.5
Jan 1 3 57.4
Jan 1 4 88.0
Jan 1 5 33.2
.
.
.
Dec 31 24 77.0
Trying to figure out whether pivot_table or groupby is a better method of pandas to use to convert time series into 8760 count data frame. Additionally, I want the output to be sorted by months NOT alphabetically. Like Jan, Feb, March, April NOT April, August..
My Code is:
p50_8760 = df.groupby(['Month', 'Day', 'Hour'])['Energy'].mean()
df_p50_8760 = p50_8760.to_frame()
The output file does not have column names or the data points count of 8760 data points.