In this python pandas program, we will join the two Dataframes along columns using the pandas library.
Steps to solve the program
- Import pandas library as pd.
- Create two dataframes using pd.DataFrame().
- Join the dataframes along the columns using pd.concat() and set axis=1.
- Print the output.
import pandas as pd
df1 = pd.DataFrame({'ID':[1,2,3],'Name':['Yash','Gaurav','Sanket'],
'Age':[30,27,28]})
df2 = pd.DataFrame({'ID':[4,3],'Name':['Tanmay','Athrva'],'Age':[26,22]})
result = pd.concat([df1,df2],axis=1)
print("New dataframe")
print(result)
Output :
New dataframe
ID Name Age ID Name Age
0 1 Yash 30 4.0 Tanmay 26.0
1 2 Gaurav 27 3.0 Athrva 22.0
2 3 Sanket 28 NaN NaN NaN