Group Datetime in panda into three hourly intervals

时间:2016-06-10 16:10:34

标签: python datetime pandas

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
...

1 个答案:

答案 0 :(得分:6)

您还没有提供太多详细信息,但您可以使用' TimeGrouper':

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

如果你的时间是索引,key参数是可选的。