0

I'm trying to combine two dataframes in Python. Each has unique columns and common columns. The Key column is the same for both files.

In the combined dataframe, I want to keep each key as two rows (1 for each timepoint) and I want values in added columns to be filled with NaN if this column was not in original timepoint

  Example

CSV 1:
Key   Make   Model  Timepoint
501   Audi   A3.       1
502   Audi   NaN       1
503   Audi   A5.       1

CSV 2:
Key   Make   Model  Engine  Timepoint
501   Audi   A3      2.0T      2
502   BMW    A4      5.6T      2
503   Audi   A2      1.4T      2


Combined Expected Result:
Key   Make   Model   Engine  Timepoint
501   Audi    A3       NaN       1
502   Audi    NaN      NaN       1
503   Audi    A5       NaN       1
501  Audi     A3       2.0T      2
502   BMW     A4       5.6T      2
503   Audi    A2       1.4T      2
leahyota
  • 29
  • 3

0 Answers0