Pedro de Sá
Pedro de Sá

Reputation: 780

Find dataframe average values for each timestamp on different days

Helo everyone,

I'm trying to find the average of my powerAC dataframe (5min interval) for each day, so I have 1 year of data and for the whole period I would like to know what was the average value at 09:05, 09:10, 09:15, for example, and so on. Here is an example:

enter image description here

And I would like my output to be as follows:

enter image description here

The closer I got to what I want was:

minute = pd.to_timedelta(powerAC.index.minute, unit='m')
powerAC.astype(float).groupby(minute).mean()

tried with powerAC.index.hour also but still doesn't provide me with my desired output. I saw many solution in here but they were all with hourly average or 5 minute average using .resample. Any help is really appreciated!

Upvotes: 0

Views: 264

Answers (2)

BENY
BENY

Reputation: 323366

Check

minute = powerAC.index.strftime('%H:%M')

Upvotes: 1

Quang Hoang
Quang Hoang

Reputation: 150805

You can do:

hhmm = pd.to_datetime(powerAC.index).strftime('%H:%M')
powerAC.astype(float).groupby(hhmm).mean()

If you want timedelta, you can do:

datetime = pd.to_datetime(powerAC.index)
hhmm = datetime - datetime.floor('D')

powerAC.astype(float).groupby(hhmm).mean()

Upvotes: 1

Related Questions