Page6/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
| How | Result |
|---|---|
inner | Only matching rows in both |
left | All rows from left, NaNs for missing right |
right | All rows from right, NaNs for missing left |
outer | All 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…