How can I merge/join these two dataframes ONLY on "id". Produce 3 new dataframes:
- 1)R1 = Merged records
- 2)R2 = (DF1 - Merged records)
- 3)R3 = (DF2 - Merged records)
Using pandas in Python.
First dataframe (DF1)
| id | name |
|-----------|-------|
| 1 | Mark |
| 2 | Dart |
| 3 | Julia |
| 4 | Oolia |
| 5 | Talia |
Second dataframe (DF2)
| id | salary |
|-----------|--------|
| 1 | 20 |
| 2 | 30 |
| 3 | 40 |
| 4 | 50 |
| 6 | 33 |
| 7 | 23 |
| 8 | 24 |
| 9 | 28 |
My solution for
R1 =pd.merge(DF1, DF2, on='id', how='inner')
I am unsure that is the easiest way to get R2 and R3
R2 should look like
| id | name |
|-----------|-------|
| 5 | Talia |
R3 should look like:
| id | salary |
|-----------|--------|
| 6 | 33 |
| 7 | 23 |
| 8 | 24 |
| 9 | 28 |