Module 11 Summary
The idea this module was built around
SQL and pandas overlap enough to be confusing and differ enough to be dangerous. The division of labour is simple once stated: aggregate in SQL, shape and visualise in pandas.
What you can now do
- Move a result set into a DataFrame without changing what it means
- Recognise which operations belong on the database side and which do not
- Assert that two routes to the same number actually agree, programmatically
The trap this module removed
Two people computing "the average" in different tools will eventually disagree, and eyeballing the outputs will not tell you who is right. The fix is an assertion that fails loudly. On the feedback table, AVG gives 3.05 while .fillna(0).mean() gives 2.68 - same data, different denominator, no warning either way.
Figures worth remembering
Completed: 988 orders averaging ₹2,718.53. Pending: 12 orders averaging ₹1,296.50. Both routes must produce these exactly. Compute at full precision and round only at display, in both tools.
The rule worth writing down
Pull the smallest result set that answers the question. Moving 4,812 rows into Python to count them is slower, more fragile, and produces a figure nobody else can reproduce from the database.
Before you move on
Add one assertion to a notebook you already use, comparing a pandas figure against the SQL that should produce it. The first time it fails will pay for the habit.
