bala chandar
bala chandar

Reputation: 99

Create third dataframe with existing two dataframe columns

I have two dataframes, and I want to create third dataframe with the columns of existing dataframes df1

╔═══════╦═══════╦════════╗
║   A   ║   B   ║   C    ║
╠═══════╬═══════╬════════╣
║ Bob   ║ David ║ George ║
║ Jon   ║ Aron  ║ Cathy  ║
║ Cathy ║ Vinod ║ Wills  ║
╚═══════╩═══════╩════════╝

df2

╔════════╦═════════╦════════╗
║   D    ║    E    ║   F    ║
╠════════╬═════════╬════════╣
║ Robert ║ Stephen ║ Martin ║
║ Arthur ║ Allen   ║ Lilly  ║
║ Kristy ║ Calvin  ║ Olive  ║
║ James  ║ Danies  ║ Harry  ║
╚════════╩═════════╩════════╝

And I need a dataframe like this with columns of df1 & df2 with same empty cells

df3

╔═══════╦════════╦═════════╦════════╗
║   B   ║   C    ║    E    ║   F    ║
╠═══════╬════════╬═════════╬════════╣
║ David ║ George ║ Stephen ║ Martin ║
║ Aron  ║ Cathy  ║ Allen   ║ Lilly  ║
║ Vinod ║ Wills  ║ Calvin  ║ Olive  ║
║       ║        ║ Danies  ║ Harry  ║
╚═══════╩════════╩═════════╩════════╝

Upvotes: 0

Views: 62

Answers (1)

Zero
Zero

Reputation: 76917

Use

In [335]: pd.concat([df1[['B', 'C']], df2[['E', 'F']]], axis=1)
Out[335]:
       B       C        E       F
0  David  George  Stephen  Martin
1   Aron   Cathy    Allen   Lilly
2  Vinod   Wills   Calvin   Olive
3    NaN     NaN   Danies   Harry

Upvotes: 2

Related Questions