0PricingLogin
Learn AI with Python · Lesson

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     80

All lessons in this course

  1. GroupBy and Aggregation
  2. Pivot Tables and Cross-Tabulation
  3. Advanced Merging and Joining
  4. Time Series in Pandas
← Back to Learn AI with Python