4

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
...
IanS
  • 15,771
  • 9
  • 60
  • 84
claude
  • 549
  • 8
  • 25

1 Answers1

7

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.

IanS
  • 15,771
  • 9
  • 60
  • 84
  • I realize that yes i haven't given all details. 1) 3T is 3 minutes, so it should be 3h (i tried and 3h transforms the datetime column in 3hourly, 2) it sums the values of the first columns, so it doesn't properly count the values. if I use .count() works! if you correct 3T to 3h and sum to count i will mark it as correct – claude Jun 10 '16 at 17:52
  • @claire thanks for the clarifications, I have edited my answer. – IanS Jun 10 '16 at 17:57