I have two pandas dataframe in python I want to concatenate on common column (eg. id)
First Source dataframe is something like this
id | col
---------
1 | h1
2 | h2
3 | h3
3 | h33
3 | h333
4 | h4
6 | h6
Target dataframe is
id | col
---------
1 | h11
2 | h2
3 | h%
3 | h3
4 | h4
6 | h6
Here, the row with id=3 has duplicates. Source dataframe with id=3 has three rows & target dataframe with id=3 has two rows. I want to be able to retain the first common number of rows (i.e two), something like this
id | col
---------
1 | h1 | h11
2 | h2 | h2
3 | h3 | h%
3 | h33 | h3
4 | h4 | h4
6 | h6 | h6
I have tried simple merge in pandas like
pd.concat(source_df , target_df, on="id")
Is there anything else I can do to achieve this logic?