0

I am working on merging multiple dataframes, whose index values are not necessarily the same. The structure of the dataframe could be as below:

     |Col1        | Col2         | Col3
-----|----     ---|------     ---|----
A    | 1        A | 7          C | 5
B    | 2        D | 8          D | 9
C    | 3        B | 9          F | 7
D    | 4        F | 10         H | 9
E    | 5        G | 11         A | 6
F    | 6        H | 12         I | 8

After merging, I should get something like the following:

      Col1    Col2   Col3
-----|----  |------|----
A    | 1    |  7   | 6
B    | 2    |  9   | -
C    | 3    |  -   | 5
D    | 4    |  8   | 9
E    | 5    |  -   | -
F    | 6    |  10  | 7
G    | -    |  11  | -
H    | -    |  12  | 9
I    | -    |  -   | 8

I tried pandas merge() and concat() without much success because of the restrictions on the indexes, without much success.

Balepur
  • 138
  • 1
  • 7
  • 1
    `pd.concat([df1, df2, df3], axis=1)` – mozway Jul 25 '23 at 10:11
  • As i said, I tried this option, but i guess that I hadn't indicated on the axis, axis=1 option. My bad! Thanks a lot... – Balepur Jul 25 '23 at 10:35
  • Which is why you should always provide the DataFrame constructors and the exact command that you used to allow others to reproduce what you tried ;) – mozway Jul 25 '23 at 11:18

0 Answers0