Skip to content Skip to sidebar Skip to footer

Pandas DataFrame Grouping By Timestamp

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 (eve

Solution 1:

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()

Post a Comment for "Pandas DataFrame Grouping By Timestamp"