0

I have two dataframes: First looks like this:

df = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AC'))

I would like to get a dataframe which looks like this:

   A  B   C
1  1  2   NaN
2  3  4   NaN
3  5  NaN 7
4  7  NaN 8

How can I get this?

Tobitor
  • 1,388
  • 1
  • 23
  • 58

1 Answers1

1

You can do:

import pandas as pd
df_merged = pd.concat([df,df2],axis = 0) # 0 means rows, which you can exclude as it is the default

it prints:

   A    B    C
0  1  2.0  NaN
1  3  4.0  NaN
0  5  NaN  6.0
1  7  NaN  8.0

which is your desired result.

sophocles
  • 13,593
  • 3
  • 14
  • 33