0

Merge two dataframes (row data) by comparing two columns containing same string values(but in different order).

dfA = pd.DataFrame({'X':['a','b','c'],'Y':['d','e','f'], 'Time':[10,20,30]})

dfB = pd.DataFrame({'X':['c','b','a'],'Z':['3','2','1'], 'T':[10,20,30]})

I want to merge the two data frames into a new one or one into another, which ever is optimal. Condition being the rows are to be merged with reference to the column X which is common in both the dataframes.

The input data

dfA= X Y Time 0 a d 10 1 b e 20 2 c f 30


dfB = 


        X   Z   T
0   c   3   10
1   b   2   20
2   a   1   30

Desired Output 

dfC =
    X   Y   Time    Z   T
0   a   d   10      1   30
1   b   e   20      2   20
2   c   f   30      3   10


Any suggestions would be a great help . Thanks in advance```



0 Answers0