Pandas DataFrame grouping by Timestamp

后端 未结 1 1079
太阳男子
太阳男子 2020-12-20 00:16

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.

相关标签:
1条回答
  • 2020-12-20 00:49

    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()
    
    0 讨论(0)
提交回复
热议问题