How two panda data frames with same column values can be merged to form the third data frame that shows the difference of the values

Refresh

2 weeks ago

Views

6 time

0

dataframe:df1

     name  age  id  salary
0   Smith   30   2    2000
1     Ron   24   3   30000
2    Mike   35   4   40000
3    Jack   21   5    5000
4  Roshan   20   6   60000
5   Steve   45   8    8000
6   Peter   32   1    1000

dataframe:df2

    name  age  salary  id
0  Peter   28   10000   1
1  Smith   30    1500   2
2    Ron   24    7000   3
3   Mike   35   20000   4
4   Jack   21    5000   5
5  Cathy   20    9000   6
6  Steve   45   56000   8

df1 and df2 To be merged on ID's.Please not that ID's are same in both df1 and df2 but id order is different.df3 needs to be created like below-

     name       age    id    salary
0   Smith        30     2    2000|1500
1     Ron        24     3    30000|7000
2    Mike        35     4    40000 |20000
3    Jack        21     5    5000
4  Roshan|Cathy  20     6    60000|9000
5   Steve        45     8    8000|56000
6   Peter        32|28  1    1000|10000

0 answers