0

I have the following data frame named target.

time_stamp user_id visited
2014-04-22 03:53:30 1 1
2013-11-15 03:45:04 2 1
2013-11-29 03:45:04 2 1
2013-12-09 03:45:04 2 1
2013-12-25 03:45:04 3 1

I would like to create a new data frame df, which has two columns user_id which are unique user_id numbers. and times which is a list of timestamps for when that user_id logged in.

I created another table to show the user id as a column and the corresponding timestamps in a list on another column but I can't publish the question because some sort of using code error keeps popping up.

iterating through the rows didn't work and I was also unsuccessful going through a for loop.

thanks

  • `df.groupby('user_id', as_index=False)['time_stamp'].agg(list)` – mozway Aug 02 '23 at 16:15
  • This question was closed because the powers that be said it was too similar to "How to group dataframe rows into list in pandas groupby". I just wanted to point out that it is only similar if you know that you need to use group by. the person that is asking might not know. When i wrote the question, I looked at the related questions and this question never came up. – Fernando Araiza Aug 02 '23 at 19:16
  • @-mozway, thank you, that did it. I tried playing around with groupby but I couldn't get it to work. – Fernando Araiza Aug 02 '23 at 19:17
  • that's fine that you didn't know. The benefit of having closed questions is also to help future readers find the answer. Even if, like you, they didn't know about `groupby` ;) – mozway Aug 02 '23 at 19:39

0 Answers0