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?
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'))