Concatenating DataFrames
pd.concat() stacks DataFrames together vertically (rows) or horizontally (columns).
Vertical Concatenation
Stack DataFrames on top of each other:
Loading Pandas Playground...
Resetting Index After Concat
Fix the duplicate indices:
Loading Pandas Playground...
Horizontal Concatenation
Add columns side by side:
Loading Pandas Playground...
Handling Different Columns
What happens with mismatched columns:
Loading Pandas Playground...
Adding Keys for Identification
Track which DataFrame each row came from:
Loading Pandas Playground...
Concatenating Multiple DataFrames
Combine many DataFrames at once:
Loading Pandas Playground...
Exercise: Stack DataFrames
Loading Exercise...
Exercise: Add Columns
Loading Exercise...
Key Points
pd.concat()combines DataFrames- Default stacks vertically (rows)
axis=1for horizontal (columns)ignore_index=Trueresets row numbersjoin='inner'keeps only common columnskeys=adds hierarchical index for tracking
Up next · Lesson 28 of 42
Merging DataFrames
1 min read
27 of 42 lessons done

Ask Byte about this lesson
A private chat about this lesson. Byte has read the whole lesson, answers in seconds, and shows the section each answer comes from. Ask follow-ups in any language.
Questions & Answers
Public questions about this lesson. The AI Tutor answers right away in your language, the FreeAcademy team checks answers, and every learner can read them.

