8

I have two pandas dataframes

df1 = DataFrame([[0,123,321],[0,1543,432]], columns=['A', 'B','C']) df2 = DataFrame([[1,124],[1,1544]], columns=['A', 'C']) 

I want to merge these so that the new dataframe would look like below

A | B | C 0 123 321 0 1543 432 1 null 124 1 null 1544 

I have tried using append and concat but nothing seems to work. Any help would be much appreciated.

1
  • adding the code-snippets for your failed attempts with append & concat will help to resolve specific errors Commented Apr 19, 2016 at 18:13

2 Answers 2

11

Concatenate the dataframes

import pandas as pd pd.concat([df1,df2], axis=0) A B C 0 0 123 321 1 0 1543 432 0 1 NaN 124 1 1 NaN 1544 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks this does the trick. I am marking this as answer because it also caters to empty dataframes. Append method doesn't work with empty dataframes.
8

from doc-ref ref try: df1.append(df2, ignore_index=True)

sample output:

 A B C 0 0 123 321 1 0 1543 432 2 1 NaN 124 3 1 NaN 1544 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.