Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Merging and Joining | Master Data Science with Python lesson | BraveProgrammer
  1. Courses
  2. /
  3. Master Data Science with Python

Lesson 25 of 60

·python

Merging and Joining DataFrames

20 minutes

Course progress42%

Merging & Joining

Combine data from multiple sources with relational operations.

merge (SQL‑like joins)

orders = pd.read_csv('orders.csv')
customers = pd.read_csv('customers.csv')

# Inner join on customer_id
merged = pd.merge(orders, customers, on='customer_id', how='inner')
(merged.head())
print

Types of joins

  • inner: keep only matches
  • left: keep all left rows
  • right: keep all right rows
  • outer: keep all rows, fill missing with NaN
left_join = pd.merge(df_left, df_right, on='key', how='left')
right_join = pd.merge(df_left, df_right, on='key', how='right')
full_outer = pd.merge(df_left, df_right, on='key', how='outer')

Concatenating vertically or horizontally

# Append rows (vertical)
combined = pd.concat([df1, df2], ignore_index=True)

# Append columns (horizontal)
combined_h = pd.concat([df1, df2], axis=1)

Handling duplicate column names after merge

merged = pd.merge(df1, df2, on='id', suffixes=('_left', '_right'))

Info

Use validate='one_to_one' or validate='many_to_one' to ensure the merge behaves as expected.
pd.merge(df_a, df_b, on='key', how='inner', validate='many_to_one')
```</Alert>
Make it stickPractice what you've learned1 quiz · 4 practical tests · Optional activities from Master Data Science with PythonBrowse activities
Previous lessonGroupBy and AggregationsContinue to lesson 26Pivot Tables and CrosstabulationsBack to Master Data Science with Python curriculum