8
votes

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.

2
adding the code-snippets for your failed attempts with append & concat will help to resolve specific errors - Joshua Baboo

2 Answers

10
votes

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
7
votes

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