Python pandas: How to match data between two dataframes

Question:

The first dataframe(df1) is similar to this:

Result A B C
2021-12-31 False True True
2022-01-01 False False True
2022-01-02 False True False
2022-01-03 True False True

df2 is an updated version of df1, the date data are new and the column names may be increased, which is similar to this:

Result A B C D
2022-01-04 False False True True
2022-01-05 True False True True
2022-01-06 False True False True
2022-01-07 False False True True

I want to integrate two databases, but I don’t know how to do it。
I want to get a result similar to the following:

Result A B C D
2021-12-31 False True True NaN
2022-01-01 False False True NaN
2022-01-02 False True False NaN
2022-01-03 True False True NaN
2022-01-04 False False True True
2022-01-05 True False True True
2022-01-06 False True False True
2022-01-07 False False True True

Thank you very much!

Asked By: xyww

||

Answers:

Use the concatenate function while ignoring indexes

df_new = pd.concat([df1, df2], ignore_index=True)

Any missing values will be ‘NaN’.

Answered By: A-T
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.