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
Relational Joins with pd.merge (Inner, Left, Right, Outer)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
HomeTutorialsPandasRelational Joins with pd.merge (Inner, Left, Right, Outer)
Reshaping Data: Melt, Stack & Unstack

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

Intermediate6 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet
Pandas Merge JoinsClick to Zoom
Pandas Merge Joins

1. What is Relational Merging?

While concat() simply glues tables together, pd.merge() combines DataFrames based on matching values in common key columns—identically to an SQL JOIN or Excel XLOOKUP / VLOOKUP.


2. The 4 Relational Join Types

1. Inner Join (how='inner' - Default)

Keeps only the rows where the join key exists in both tables (the intersection):

1import pandas as pd
2 
3df_customers = pd.DataFrame({
4 'Cust_ID': [1, 2, 3, 4],
5 'Name': ['Amit', 'Priya', 'Rohan', 'Sneha']
6})
7 
8df_orders = pd.DataFrame({
9 'Cust_ID': [2, 3, 5],
10 'Order_Amount': [4500, 7200, 1900]
11})
12 
13# Inner join: only customers 2 and 3 match!
14inner_df = pd.merge(df_customers, df_orders, on='Cust_ID', how='inner')
15print(inner_df)

2. Left Join (how='left')

Keeps all rows from the left table. If no match exists in the right table, right-side columns are filled with NaN:

1# Keeps all customers (Amit, Priya, Rohan, Sneha)
2left_df = pd.merge(df_customers, df_orders, on='Cust_ID', how='left')

3. Right Join (how='right')

Keeps all rows from the right table. Customer 5 (who is not in the customer master table) is included:

1right_df = pd.merge(df_customers, df_orders, on='Cust_ID', how='right')

4. Full Outer Join (how='outer')

Keeps all rows from both tables, unioning unmatched records with NaN:

1outer_df = pd.merge(df_customers, df_orders, on='Cust_ID', how='outer')

3. Merging on Differently Named Columns

When the left table calls the key client_id and the right table calls it cust_number:

1merged_df = pd.merge(
2 df_left,
3 df_right,
4 left_on='client_id',
5 right_on='cust_number',
6 how='left'
7)

4. Detecting Unmatched Records with indicator=True

To audit which table contributed each record (essential for data reconciliation):

1audit_df = pd.merge(df_customers, df_orders, on='Cust_ID', how='outer', indicator=True)
2print(audit_df['_merge'].value_counts())

Output:

1both 2
2left_only 2
3right_only 1
4Name: _merge, dtype: int64

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the default join type used in pd.merge(df1, df2, on='key')?
Question 2
When joining two DataFrames where the key column is named 'emp_id' in the left table and 'employee_number' in the right table, which parameters must be used?
Question 3
What does setting indicator=True add to the merged DataFrame?
Question 4
Which join type preserves every single record from the left DataFrame regardless of whether a matching record exists in the right table?
Question 5
What parameter resolves overlapping column names (e.g., both tables have a 'Date' column) during a merge?

Next Lesson

Reshaping Data: Melt, Stack & Unstack

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

Related Lessons

Previous LessonNext Lesson
Concatenating DataFrames (pd.concat)Reshaping Data: Melt, Stack & Unstack

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