0

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  ║
╚═══════╩════════╩═════════╩════════╝
1
  • I can't see in your question what have you already tried. Commented Feb 19, 2018 at 11:53

1 Answer 1

2

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