I have a DataFrame which has a datetimeindex ranging from 2004-01-01 01:00
to 2014-12-31- 00:00
2004-01-01 00:00:00+01:00
2004-01-01 01:00:00+01:00
2004-01-01 02:00:00+01:00
2004-01-01 03:00:00+01:00
.
.
.
2014-12-30 22:00:00+01:00
2014-12-30 23:00:00+01:00
2014-12-31 00:00:00+01:00
Id like to find all days and months and hours that are equal independent of year and take the mean of those values.
E.g. If I ask for "YYYY-01-01 01:00"
I'd be taking the mean of those values stored in the indexes
"2004-01-01 01:00", "2005-01-01 01:00", "2006-01-01 01:00", "2007-01-01 01:00", "2008-01-01 01:00", "2009-01-01 01:00", "2010-01-01 01:00", "2011-01-01 01:00",
"2012-01-01 01:00", "2013-01-01 01:00", "2014-01-01 01:00"
I tried creating a new year with hourly frequency and loop over all dates but those take forever. df_inflow is the DataFrame with the index from 2004 to 2014 which is given by the function inflow()
date_range = pd.date_range(start=pd.to_datetime('2019-01-01'),
end=pd.to_datetime('2019-12-31'), tz='Europe/Oslo', freq='H')
df_inflow = inflow()
for date in date_range:
temp_inflow = df_inflow.loc[(df_inflow.index.strftime('%m-%d %H') ==
date)].mean()[0]
# Save mean