'How Do I match two Data Frames in Pandas with multiple matches?

I have 2 data frames I want to match some data from one data frame and append it on another.

df1 looks like this:

sourceId firstName lastName
1234 John Doe
5678 Sally Green
9101 Chlodovech Anderson

df2 looks like this:

sourceId agentId
123456789 1234,5678
987654321 9101
143216546 1234,5678

I want my Final Data Frame to look like this:

sourceId firstName lastName agentId
1234 John Doe 123456789,143216546
5678 Sally Green 123456789,143216546
9101 Chlodovech Anderson 987654321

Usually appending stuff is easy but I'm not quite sure how to match this data up, and then append the matches with commas in-between them. I'm fairly new to using pandas so any help is appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source