Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group Datetime in panda into three hourly intervals

I want to modify this SO topic here to three hourly interval. I have a database of events at minute resolution. I need to group them in three hourly, and extract the count of this grouping.

The output would ideally look something like a table like the following:

3hourly    count
0          10
3          3
6          5
9          2
...
like image 753
claude Avatar asked Mar 12 '23 00:03

claude


1 Answers

You haven't provided much detail, but you can use the 'TimeGrouper':

df.groupby(pd.TimeGrouper(key='your_time_column', freq='3H')).count()

The key parameter is optional if your time is the index.

like image 110
IanS Avatar answered Mar 17 '23 18:03

IanS