0

Input is as follows:

userid,sessionid,phone,startdt,endt
1,1,samsung,03/04/22,03/05/22
1,2,iphone,03/05/22,03/06/22
1,3,htc,03/06/22,03/06/22
1,4,iphone,03/06/22,03/07/22
2,1,samsung,03/04/22,03/05/22
3,1,iphone,03/04/22,03/06/22

Output is as follows:

userid,sessionid,phone,startdt,endt
1,4,iphone,03/06/22,03/07/22
2,1,samsung,03/04/22,03/05/22
3,1,iphone,03/04/22,03/06/22

Group by user id and take max of sessionid and print the corresponding column values The following is what I came up with df1.groupby("userid").agg({'sessionid':'max','phone':'first'})

Echchama Nayak
  • 1,162
  • 2
  • 21
  • 38

0 Answers0