Python Practice › Pandas Programs › Program 80

Join along columns

EasyPandas Programs · 80 of 95

Write a pandas program to join two DataFrames side by side.

Advertisement
Output
     Name  Age    City
0    Yash   30    Pune
1  Gaurav   27  Nagpur
2  Sanket   28     NaN

Approach

  1. pd.concat([d1, d2], axis=1); missing rows become NaN.

Solution

Python
import pandas as pdd1 = pd.DataFrame({"Name": ["Yash", "Gaurav", "Sanket"], "Age": [30, 27, 28]})d2 = pd.DataFrame({"City": ["Pune", "Nagpur"]})print(pd.concat([d1, d2], axis=1))
Output
     Name  Age    City
0    Yash   30    Pune
1  Gaurav   27  Nagpur
2  Sanket   28     NaN
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs