Groupby first two earliest dates, then average time between first two dates - pandas

后端 未结 3 789
闹比i
闹比i 2021-01-27 17:43

I\'m hoping to groupby users and find the first two uploads. I\'ve figured out how to get the first date via minimum, but I\'m having trouble getting that second upload date. Th

3条回答
  •  忘了有多久
    2021-01-27 18:27

    Using sort_values + head

    df.sort_values('Date_Uploaded').groupby('User_ID').head(2)
    Out[152]: 
      Date_Uploaded User_ID Display_Status
    6    2018-07-25  efg123        Pending
    5    2018-08-01  efg123        Pending
    3    2018-09-21  abc123        Pending
    0    2018-10-27  abc123        Cleared
    

提交回复
热议问题