Dmitry Mottl
Dmitry Mottl

Reputation: 862

Create the most complete table from two tables with missing rows in pandas

I have two pandas DataFrames df1 and df2:

df1:      df2:

   A         A

1 10      2 21
2 20      3 31
5 50      4 41
6 60      5 51

and want to merge both DataFrames to the most complete one based on their indexes. The result should be the following:

df_full

   A

1 10
2 20
3 31
4 41
5 50
6 60

Upvotes: 0

Views: 31

Answers (1)

yatu
yatu

Reputation: 88266

You have combine_first for this:

df1.combine_first(df2).astype(int)

    col1
1    10
2    20
3    31
4    41
5    50
6    60

Upvotes: 3

Related Questions