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?
Asked
Active
Viewed 663 times
0

Henry Ecker
- 34,399
- 18
- 41
- 57

Rick45888
- 155
- 1
- 2
- 9
1 Answers
0
This is the answer
df.groupby('unique_id').agg(', '.join)

Henry Ecker
- 34,399
- 18
- 41
- 57

Rick45888
- 155
- 1
- 2
- 9
-
1Your 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