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()))