0

I have a DataFrame of about a million records with multiple columns including a column for unique_id. This column has about 500,000 unique IDs. I want to aggregate the information of the 10+ columns in a single row per unique id. Ideally, it'd be a string concatenation with a , between the groups. I have done a groupby on my id column but I'm not sure where to go from here. Anybody know how to do this?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Rick45888
  • 155
  • 1
  • 2
  • 9

1 Answers1

0

This is the answer

df.groupby('unique_id').agg(', '.join)
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Rick45888
  • 155
  • 1
  • 2
  • 9
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 28 '22 at 16:53