I have some time series data that spans multiple days, like so:
dr = pd.date_range('01-01-2020 9:00', '01-03-2020 23:59', freq='1T')
df = pd.DataFrame({'data': 1}, index=dr) # all ones in the data column
I am interested in grouping by the time of day and summing the data (i.e., combine data across dates). I have gotten from this post and this one that you group data into the hour of the day by using the time attributes of a datetime series or index, like so:
df.groupby(df.index.hour).sum()
df.groupby(df.index.time).sum()
However, I want to group into 15 minute bins, e.g. something like this (numbers are arbitrary):
data
00:00 10
00:15 12
00:30 15
...
11:30 16
11:45 20
Note that I do not want to just do a 15 minute resample (e.g. df.resample('15T').sum()
), as this doesn't group similar times across days. So for example, data between 9:00 and 9:15 on any date should be placed in the same bin.
I can't find a time attribute that would achieve this. How can I do so?