'How to merge all records by their unique ID in a dataframe? [duplicate]

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?



Solution 1:[1]

This is the answer

df.groupby('unique_id').agg(', '.join)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Henry Ecker