I'm trying to create a dataframe using the values in two columns in a dataframe , this are how they look:
df1
W F1 F2
0 'AB CD' 'RS TU'
0 'BC EF' 'GH IJ'
1 'BC EF' 'NO PQ'
0 'GH IJ' 'AB CD'
1 'KL MN' 'RS TU'
0 'NO PQ' 'UV WX'
...
df2
F1 F2 BO_F1 BO_F2
'AB CD' 'GH IJ' -150 500
'BC EF' 'TG IP' 265 -150
'BC EF' 'NO PQ' -500 250
'BC EF' 'GH IJ' 600 -700
'KL MN' 'PP UY' 150 -600
'RS TU' 'AB CD' -400 350
...
What I want:
W F1 F2 BO_F1 BO_F2
0 'AB CD' 'RS TU' -400 350
0 'BC EF' 'GH IJ' 600 -700
1 'BC EF' 'NO PQ' -500 250
0 'GH IJ' 'AB CD' -150 500
1 'KL MN' 'RS TU' -600 700
0 'NO PQ' 'UV WX' 350 -900
I want to merge the columns BO_F1
and BO_F2
from df2 to df1 based on the values of columns F1
and F2
. The main problem I'm having is that some combinations of values are swapped, for example
in df1 the first combination in F1
and F2
is AB CD
and RS TU
but such values in df2 are swapped, this is, F1
and F2
are RS TU
and AB CD
.
How can I achieve this?