Reputation: 279
I have a use case where:
Data is of the form: Col1, Col2, Col3 and Timestamp.
Now, I just want to get the counts of the rows vs Timestamp Bins.
i.e. for every half hour bucket (even the ones which have no correponding rows), I need the counts of how many rows are there.
Timestamps are spread over a one year period, so I can't divide it into 24 buckets.
I have to bin them at 30 minutes interval.
Upvotes: 6
Views: 6988
Reputation: 402303
groupby
via pd.Grouper
# optionally, if needed
# df['Timestamp'] = pd.to_datetime(df['Timestamp'], errors='coerce')
df.groupby(pd.Grouper(key='Timestamp', freq='30min')).count()
resample
df.set_index('Timestamp').resample('30min').count()
Upvotes: 19