0

I have these two dataframes:

df1 =
ID a b c d pred_1
1  ...       0
3  .         1
4  .         1
5            0
8            0 

df2 =
ID a b c d pred_2
2  ...       1
3  .         1
6  .         0
5            0
7            1 
9            1

So some of the IDs occur in both dataframes and all column names are the same except the prediction column. And I would like to merge them like this:

df3 =
ID a b c d pred_1 pred_2
1  ...       0      0
2  .         0      1
3  .         1      1
4            1      0     
5            0      0
6            0      0
7            0      1
8            0      0
9            0      1

I don't know how to put it in prettier words. But can anybody help me please?

John
  • 91
  • 7

1 Answers1

0

You can use pd.merge(..., how='outer')

pd.merge(df1, df2, how='outer').fillna(0)

T C Molenaar
  • 3,205
  • 1
  • 10
  • 26