Skip to content
Justice Tech School

merge

merge joins two tables on a key like SQL joins.

Example
a = pd.DataFrame({"id": [1, 2, 3], "name": ["Ada", "Kofi", "Amina"]})
b = pd.DataFrame({"id": [1, 2, 4], "score": [90, 70, 60]})
print(a.merge(b, on="id"))
print(a.merge(b, on="id", how="left"))

Result

   id  name  score
0   1   Ada     90
1   2  Kofi     70
   id   name  score
0   1    Ada   90.0
1   2   Kofi   70.0
2   3  Amina    NaN

Exercise

Join on a key.

a.(b, on="id")

Quiz Test

Default join type?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.