Home > database >  Two dataframes merge, groupby, aggregate by conctatenating values in a column
Two dataframes merge, groupby, aggregate by conctatenating values in a column

Time:12-25

I have two dataframes that I want to merge using left join, and bring only Codes from second dataframe but to show its values in a single string comma separated.

What is the best way to do this?

Simplified view

CodePudding user response:

Use a combination of merge and groupby.agg:

df1.merge(df2.groupby('DF2_ID2', as_index=False).agg(', '.join), on='DF2_ID'))
  • Related