runtime

compare approaches one problem · two ways

Compare Approaches

The same problem solved different ways in Python, run on the same input, with what really differs and when to use each.

pandas merge vs SQL JOIN

Revenue per customer segment: join orders to customers.

what differs

merge(how="inner") is SQL's INNER JOIN; how="left" is LEFT JOIN. pandas also offers indicator=True (which side each row came from) and validate="many_to_one" to catch duplicated keys.

at a glance

approachuse it when
A · DataFrame.mergeWorking in pandas already; how=, indicator= and validate= help find join problems.
B · SQL JOINJoining tables that live in a database, especially large ones with indexes.

Watch out: Duplicate keys on both sides multiply rows in both tools. Rounding the sum before or after can change the last cent.

the outputs

Each approach runs on the same input.

concepts

joinsmerge

learn it

Merging tables

related comparisons

pandas groupby vs SQL GROUP BY · Joining records: nested loops vs a dict index

Uses the Online Store dataset.

A · DataFrame.merge
B · SQL JOIN
Compare Python Approaches · Runtime