I have a pandas data frame with session ID's, URL and TimeStamp in the following format:
SessionId TimeStamp URL
aa420858 20:24 url1
aa420858 20:26 url2
aa420858 20:27 url3
bb779bc3 18:18 other_url1
bb779bc3 18:21 other_url2
bb779bc3 18:24 other_url3
bb779bc3 18:25 other_url4
zz920853 20:27 diff_url1
zz920853 20:28 diff_url2
I need to get the following format:
SessionId URL1 URL2 URL3 URL4 TimeStamp1 TimeStamp2 TimeStamp3 TimeStamp4
aa420858 url1 url2 url3 20:26 20:27 20:27
bb779bc3 other_url1 other_url2 other_url3 other_url4 18:18 18:21 18:24 18:25
zz920853 diff_url1 diff_url2 20:27 20:28
I never know in advance a number of url's per session.
I tried to use pd.melt, pd.pivot_table, pivot(), unstack() and so on, but not successful. Can someone please advise the best approach. Also, would it be possible to use difference in time stamps to get time on a page?
Thank you very much!