all cheat sheets

pandas merge and concat cheat sheet

SQL-style joins with merge, stacking frames with concat, and validating join keys.

INNER JOIN

LEFT JOIN

RIGHT JOIN

FULL JOIN

merge

Inner / left join
df.merge(depts, on="dept", how="left")
Different key names
orders.merge(customers, left_on="customer_id", right_on="id")
Anti-join with indicator
m = df.merge(depts, on="dept", how="left", indicator=True)
m[m["_merge"] == "left_only"]
Guard against duplicates
df.merge(depts, on="dept", validate="many_to_one")

concat

Stack rows
pd.concat([df_2023, df_2024], ignore_index=True)
Side by side
pd.concat([a, b], axis=1)

Try it live

python · editable
loading editor…

Practice it

learn pandas step by step →

More cheat sheets

Ready for interview-level questions? Pro unlocks the full company problem set.