0

I have two data frames.

df1
    id  Sales               
0   1   5000
1   2   234
2   13  456
3   34  231
4   5   679
5   6   643
6   7   6789
7   8   432
8   9   345
9   10  678

df2
    id1     Sales Total
0   34      85
1   51      234
2   23      65
3   35      2349
4   2       6146
5   8       432
6   12      32
7   231     582
8   45      610
9   78      259
10  5       679
11  6       6738
12  18      982
13  87      719
14  345     955
15  2356    372

The id column and id1 column are unique and I want to merge/map these two data frames using the id column and id1 column. However, when I do that I want to keep all four columns to keep comparing the id and sales. So I want to find a matching id from the id1 column and bring id1 and sales total columns to the df1 and make a row in front of the same id. If there isn't any matching value I want to enter Sales Total column zero in that row. If there are not matching id1 in df2 I want to get that too.

So final out come should be look like below.

    id      Sales   id1     Sales Total
0   1       5000    1       0
1   2       234     2       6146
2   13      456     13      0
3   34      231     34      85
4   5       679     5       679
5   6       643     6       6738
6   7       6789    7       0
7   8       432     8       432
8   9       345     9       0
9   10      678     10      0
10  NaN     NaN     51      234
11  NaN     NaN     23      65
12  NaN     NaN     35      2349
13  NaN     NaN     12      32
14  NaN     NaN     231     582
15  NaN     NaN     45      610
16  NaN     NaN     78      259
17  NaN     NaN     18      982
18  NaN     NaN     87      719
19  NaN     NaN     345     955
20  NaN     NaN     2356    372

Is it possible to do it using python?

Can someone give me an idea, please?

Anything is appreciated. Thanks in advance!

rra
  • 655
  • 4
  • 14

0 Answers0