Python Practice › Pandas Programs › Program 80
Join along columns
Write a pandas program to join two DataFrames side by side.
Output
Name Age City 0 Yash 30 Pune 1 Gaurav 27 Nagpur 2 Sanket 28 NaN
Approach
pd.concat([d1, d2], axis=1); missing rows become NaN.
Solution
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
Learn the concept
New to this topic? Read the lesson, then come back.