'dataframe merge based on three matching columns

Thank you for helping, I really have trouble with the merge of dataframes (I wanna merge two frames with the following conditions) ,however it fails "Unintended result in merged dataframes yellow-highlighted in picture 3).

I wanna merge based on the first two columns. For row, 1). If column one and two in the two frames matched together. --> then combine into a single row. 2). If either column one or two do not match in the two frames , but the other one matched --> create a new row. 3). If both column one and two do not match in the two frames --> create a new row.

Dataframe (1)

enter image description here

Dataframe (2) enter image description here

enter image description here



Solution 1:[1]

You can try specifying a list of columns to merge on.

Output_list_sort[0].merge(Output_list_sort[1], on=['??', '?', '??'], how='inner')

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 greco