I have a dataframe df1
that just has columns From
and To
. I have a separate dataframe df2
that contains columns Source
and Destination
among others. I want to merge df1
and df2
either by matching From
and To
on Source
and Destination
OR by matching To
and From
on Source
and Destination
. In other words I want to check for both A->B and B->A. Is there an easy way to do this? I want the resulting dataframe to have all of the information from df1
.
In [2]: df1
Out[2]:
To From
0 1 2
1 1 3
2 4 6
In [2]: df2
Out[2]:
Source Destination
0 1 2
1 10 13
2 6 4
Here, I would want it to merge on the 1 and 2 (row 0) but also it should merge the 4/6 row on 6/4.