1

I'm trying to merge two dataframes of different lengths, but I want to preserve the length of the longer one and insert nans where the shorter one doesn't match.

Example:

df1                      df2                 merged df
0  1  2  3               0  4  5             0  1  2  3  4  5
a1 b1 c1 d1              a1 e1 f1            a1 b1 c1 d1 e1 f1
a2 b2 c2 d2              a2 e2 f2            a2 b2 c2 d2 e2 f2
a3 b3 c3 d3                                  a3 b3 c3 d3 NaN NaN

I'm currently using for loops, but there has to be a better alternative.

morhc
  • 194
  • 11

0 Answers0