Skip to main content
Practice

Merging and Joining DataFrames

In real-world data tasks, information is often spread across multiple tables.

For example, one DataFrame might hold customer information, while another contains their orders.

To analyze them together, you'll need to merge or join the datasets.


Merge and Join Basics

Pandas provides flexible tools for combining data:

  • pd.merge() combines rows from two DataFrames based on matching column values, similar to SQL joins.
  • .join() is a method that adds columns from one DataFrame to another using the index or a key column.

Common Join Types

Join TypeDescription
InnerKeeps only matching rows (default).
LeftKeeps all rows from the left DataFrame and adds matches from the right.
RightKeeps all rows from the right DataFrame and adds matches from the left.
OuterKeeps all rows from both DataFrames; missing values are filled with NaN.

These joins let you control how much data you include, whether you want a strict match or a full combination.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.