Python Practice › Pandas Programs › Program 79
Join along rows
Write a pandas program to join two DataFrames along rows.
Output
Id Name Age 0 1 Yash 30 1 2 Gaurav 27 2 3 Sanket 28 3 4 Atharva 26 4 5 Tanmay 22
Approach
pd.concat([d1, d2], ignore_index=True).
Solution
import pandas as pdd1 = pd.DataFrame({"Id": [1, 2, 3], "Name": ["Yash", "Gaurav", "Sanket"], "Age": [30, 27, 28]})d2 = pd.DataFrame({"Id": [4, 5], "Name": ["Atharva", "Tanmay"], "Age": [26, 22]})print(pd.concat([d1, d2], ignore_index=True))Output
Id Name Age 0 1 Yash 30 1 2 Gaurav 27 2 3 Sanket 28 3 4 Atharva 26 4 5 Tanmay 22
Learn the concept
New to this topic? Read the lesson, then come back.