Apr-20-2024, 12:53 PM
Can't see how to get what you want, but somewhere near it.
Given
df4 = df3[['col2_left', 'col2_right']]
Given
Output:df1
col1 col2
0 1 A
1 1 B
2 2 C
3 5 Z
4 4 Q
andOutput:df2
col1 col2
0 1 A
1 1 B
2 2 E
3 3 X
4 4 R
5 4 S
df3 = df1.merge(df2, how="outer", left_index=True, right_index=True, suffixes=('_left', '_right'))df4 = df3[['col2_left', 'col2_right']]
Output:df4
col2_left col2_right
0 A A
1 B B
2 C E
3 Z X
4 Q R
5 NaN S