MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Concatenating DataFrames (pd.concat)0%
Study MaterialsCheatsheet
PandasProgress 0%
1.1What is Pandas & Core Architecture1.2Pandas Installation & Environment Setup1.3Creating Series & DataFrames from Scratch
7.1Concatenating DataFrames (pd.concat)7.2Relational Joins with pd.merge (Inner, Left, Right, Outer)7.3Reshaping Data: Melt, Stack & Unstack
HomeTutorialsPandasConcatenating DataFrames (pd.concat)
Relational Joins with pd.merge (Inner, Left, Right, Outer)

Concatenating DataFrames (pd.concat)

Intermediate6 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. What is Concatenation?

Concatenation is the operation of stitching two or more DataFrames together along an axis—either stacking them vertically (adding more rows) or pasting them horizontally (adding more columns).

In Pandas, this is executed via pd.concat().


2. Vertical Concatenation: Stacking Rows (axis=0)

The most common use case is combining monthly or regional files that share the same schema:

1import pandas as pd
2 
3# Monthly sales reports
4df_jan = pd.DataFrame({'Emp': ['Aarav', 'Priya'], 'Sales': [45000, 52000]})
5df_feb = pd.DataFrame({'Emp': ['Rohan', 'Sneha'], 'Sales': [48000, 61000]})
6 
7# Stack rows vertically
8# CRITICAL TIP: Always use ignore_index=True to reset row numbering to 0, 1, 2, 3!
9df_q1 = pd.concat([df_jan, df_feb], axis=0, ignore_index=True)
10print(df_q1)

Output:

1 Emp Sales
20 Aarav 45000
31 Priya 52000
42 Rohan 48000
53 Sneha 61000

3. Horizontal Concatenation: Pasting Columns (axis=1)

When you have matching rows and want to attach additional feature columns:

1df_scores = pd.DataFrame({'Math': [92, 85], 'Science': [88, 90]})
2df_info = pd.DataFrame({'Name': ['Deepak', 'Ananya']})
3 
4# Combine columns horizontally
5df_full = pd.concat([df_info, df_scores], axis=1)
6print(df_full)

4. Tracking Data Source with Hierarchical Keys

When combining files from different branches or years, you can preserve their origin using the keys argument:

1df_combined = pd.concat([df_jan, df_feb], keys=['Jan_2026', 'Feb_2026'])
2print(df_combined)

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Which function is used in Pandas to concatenate multiple DataFrames together along an axis?
Question 2
What does ignore_index=True do in pd.concat([df1, df2], ignore_index=True)?
Question 3
Which parameter controls whether concatenation happens by rows (vertically) or by columns (horizontally)?
Question 4
What happens when concatenating two DataFrames vertically if one DataFrame has a column that the other lacks?
Question 5
How can you identify the origin of each row when concatenating multiple DataFrames?

Next Lesson

Relational Joins with pd.merge (Inner, Left, Right, Outer)

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Pivot Tables & Cross-Tabulations (pivot_table, crosstab)Relational Joins with pd.merge (Inner, Left, Right, Outer)

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

12-Month Data Analysis Mastery Program

Master Full-Stack Data Analytics (Excel, SQL, Python, Power BI & Tableau)

Combine 15 complete courses, 150 chapters, 541 topics, live SQL/Power BI/Tableau dashboards, and Scikit-Learn capstones at MSK Institute Shikohabad or Live Online.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext