0

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.

formicaman
  • 1,317
  • 3
  • 16
  • 32
  • Please see [How to make good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and provide a [mcve] including desired output and code for what you've tried so far, and what was wrong with your attempts – G. Anderson May 07 '20 at 20:31
  • Added an example. – formicaman May 07 '20 at 20:48
  • 1
    would you be able to show the expected result? the last line:`I want the resulting dataframe to have all of the information from df1` confuses me – MattR May 07 '20 at 20:59

0 Answers0