Issue
I tried to find the answer in the official Pandas documentation, but found it more confusing than helpful. Basically I have two dataframes with overlapping, but not identical column lists:
df1:
A B
0 22 34
1 78 42
df2:
B C
0 76 29
1 11 67
I want to merge/concatenate/append them so that the result is
df3:
A B C
0 22 34 nan
1 78 42 nan
2 nan 76 29
3 nan 11 67
Should be fairly simple, but I've tried several intuitive approaches and always got errors. Can anybody help me?
Solution
You need merge with parameter how = outer
df3 = df1.merge(df2, how = 'outer')
A B C
0 22.0 34 NaN
1 78.0 42 NaN
2 NaN 76 29.0
3 NaN 11 67.0
Answered By - Vaishali
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.