emrata
emrata

Reputation: 43

Merge multiple columns together based on a common column value in pandas - python

I want to merge rows based on a common value i.e date of purchase.

Dataframe

Output

How do i do this ?

Upvotes: 0

Views: 47

Answers (1)

Soumendra Mishra
Soumendra Mishra

Reputation: 3663

You can try this:

df = df.groupby(['DateOfPurchase'])['Item'].apply(','.join).reset_index()
print(df)

Output:

  DateOfPurchase        Item
0    19-Aug-2020  Apple,Eggs
1    20-Aug-2020      Banana

Upvotes: 1

Related Questions