Python Pandas program to join the two Dataframes along columns

In this python pandas program, we will join the two Dataframes along columns using the pandas library.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create two dataframes using pd.DataFrame().
  3. Join the dataframes along the columns using pd.concat() and set axis=1.
  4. 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
				
			

join the two Dataframes along rows

join the two Dataframes using the common column of both Dataframes

Leave a Comment