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.

Python loops vs pandas

Revenue per channel without cancelled orders.

what differs

The loop handles one row at a time in Python. pandas filters with a boolean mask over the whole column and groups in compiled code.

at a glance

approachuse it when
A · loop over rowsSmall data, simple logic, or no pandas available.
B · pandasAnything beyond a few thousand rows, or several steps of analysis.

Watch out: Float sums can differ in the last digits when added in a different order; both round before printing.

the outputs

Each approach runs on the same input.

concepts

vectorisationboolean masksgroupby

learn it

Filtering rows · Group and aggregate

related comparisons

pandas groupby vs SQL GROUP BY · DataFrame.apply vs vectorised columns

Uses the Online Store dataset.

A · loop over rows
B · pandas
Compare Python Approaches · Runtime