Advanced Merging and Joining
pd.merge() with how, on, left_on/right_on, suffixes, merge_asof for time-based joins.
Combining DataFrames
pd.merge joins two DataFrames on shared keys, exactly like a SQL JOIN. Mastering the how options is essential for relational data work.
import pandas as pd
left = pd.DataFrame({"id": [1, 2, 3], "name": ["a", "b", "c"]})
right = pd.DataFrame({"id": [2, 3, 4], "score": [90, 80, 70]})Inner Join (default)
how="inner" keeps only keys present in BOTH frames. It is the default.
print(pd.merge(left, right, on="id", how="inner"))
# id name score
# 0 2 b 90
# 1 3 c 80All lessons in this course
- GroupBy and Aggregation
- Pivot Tables and Cross-Tabulation
- Advanced Merging and Joining
- Time Series in Pandas