Home > Software engineering >  How to resample time series dataframe to show average hourly data?
How to resample time series dataframe to show average hourly data?

Time:11-26

I am aware that pandas resample function has **hourly ** rule. However, it returns the average for every hour for the whole dataset.

When using that method (df.Value.resample('H').mean()), I get the following output:

Time&date Value
2021-01-01 00:00:00 23
2021-01-01 01:00:00 25

However, I would like hourly resample of data which shows the average values throughout the year for the whole dataset (not everyday hourly).

What I want:

Time&date Value
00:00:00 55
01:00:00 24

Thanks in advance.

CodePudding user response:

groupby can give you the result you want. Can you try this?

dfx=df.groupby(df['date_column'].dt.hour).mean()

  • Related