1

I have two dfs that I want to concat

(sorry I don't know how to properly recreate a df here)

A  B
a1 b1
a2 b2
a3 b3

A  C
a1 c1
a4 c4

Result:

A  B C
a1 b1 c1
a2 b2 NaN
a3 b3 NaN
a4 NaN c4

I have tried:

merge = pd.concat([df1,df2],axis = 0,ignore_index= True)

but this seems to just append the second df to the first df

Thank you!

1 Answer 1

2

I believe you need an outer join:

>>> pd.merge(df,df2,how='outer')

    A    B    C
0  a1   b1   c1
1  a2   b2  NaN
2  a3   b3  NaN
3  a4  NaN   c4
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.