6/14
Merging & Joining Data · Page 1 of 1

SQL-Style Joins

Merging & Joining Data

Real data is rarely in one table. You often have a users table and a transactions table that need to be combined.

pd.merge()

Works exactly like SQL JOIN:

pd.merge(left_df, right_df, on='id', how='inner')

Types of Joins

HowResult
innerOnly matching rows in both
leftAll rows from left, NaNs for missing right
rightAll rows from right, NaNs for missing left
outerAll rows from both (fills NaNs everywhere)

pd.concat()

Use this to stack DataFrames vertically (rows) or horizontally (columns) when they share the same structure.

main.py
Loading...
OUTPUT
Click "Run Code" to execute…