Home > front end >  Merge words from a specific column into a row when other columns values are the same
Merge words from a specific column into a row when other columns values are the same

Time:11-16

I have dataframe

user friend food
mary alex fries
mary eric fries

How do I get the following dataframe

user friend food
mary alex eric fries

CodePudding user response:

I think you need join only unique values per user, then aggregate lambda function:

df = df.groupby('user', as_index=False).agg(lambda x: ' '.join(x.unique()))
  • Related