Merging pandas columns (one-to-many)

Viewed 18906

I am new to Python’s Pandas. I want to combine several Excel sheets by a common ID. Besides, there it is a one-to-many relationship.

Here are the inputs:

df1:

ID Name
3763058 Andi
3763077 Mark

df2:

ID Tag
3763058 item1
3763058 item2
3763058 item3
3763077 item4
3763077 item5
3763077 item6

I would now like to merge the two pandas data frames df1 and df2 into the following output (the column tag is merged in a single column per ID):

ID Name Tag
3763058 Andi item1, item2, item3
3763077 Mark item4, item5, item6

Could anybody please help me with this?

Cheers, Andi

1 Answers
Related