0

I have 3 dataFrames and all 3 have different columns. How do I make 1 big dataFrame of it?

Example of df1:

   type - country 
0  001  - US      
1  002  - DE      
2  003  - ES     
3  004  - FR  

Example of df2:

   Model
0  Clio
1  Q5  
2  RS6
3  AMG

Example of df3:

   Name
0  Richard
1  Paul
2  Juan
3  Del Castillo

This is the code I'm using:

df123 = pd.concat([df1, df2, df3])

The output is:

   type - country - Model - Name
0  001  - US      - NaN   - NaN
1  002  - DE      - NaN   - NaN
2  003  - ES      - NaN   - NaN 
3  004  - FR      - NaN   - NaN

Expected output:

   type - country- Model - Name
0  001  - US     - Clio  - Richard
1  002  - DE     - Q5    - Paul
2  003  - ES     - RS6   - Juan
3  004  - FR     - AMG   - Del Castillo
2
  • 1
    Try pd.concat([df1, df2, df3], axis=1)? Commented Aug 27, 2020 at 8:37
  • What is the difference between your answer and the answers below? Commented Aug 27, 2020 at 8:51

2 Answers 2

1

Try

out = df1.join([df2, df3])
Sign up to request clarification or add additional context in comments.

2 Comments

This one looks great. Its the same as Roxy. Is this called a left join?
Yes, by pandas default its left join on dataframes indexes. Read the docs here: pandas.pydata.org/pandas-docs/stable/reference/api/… :)
1
import pandas as pd

df1 = pd.DataFrame(data={'Type': ['001', '002'], 'country': ['US', 'DE']})
df2 = pd.DataFrame(data={'Model': ['Clio', 'Q5']})
df3 = pd.DataFrame(data={'Name': ['John', 'Mary']})

df = df1.join([df2, df3])

print(df)

The output would be:

  Type country Model  Name
0  001      US  Clio  John
1  002      DE    Q5  Mary

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.