Counting frequency of values by date using pandas

后端 未结 3 767
一个人的身影
一个人的身影 2020-12-28 16:00

Let\'s suppose I have following Time Series:

Timestamp              Category
2014-10-16 15:05:17    Facebook
2014-10-16 14:56:37    Vimeo
2014-10-16 14:25:16         


        
3条回答
  •  旧时难觅i
    2020-12-28 16:24

    To be a little bit more clear, you do not need to create a new column called 'week_num' first.

    df.groupby(by=lambda x: "%d/%d" % (x.week(), x.year())).Category.value_counts()
    

    The function by will automatically call on each timestamp object of the index to convert them to week and year, and then group by the week and year.

提交回复
热议问题