By the end of this lesson you will have a state-by-month sales pivot, a month-on-month comparison that doesn't fool anyone with percentages, a GST column consistency check, and the same numbers confirmed by an Excel or Sheets pivot.
You need: sales_clean.csv from lesson 2 open in your workbench, and Excel or Google Sheets · Time: 8 minutes
You already know pivot tables from Excel. Python has the same idea under two names:
- groupby: split the rows into piles by one column (one pile per state), then do one calculation per pile (add up Taxable Value). The result is a short list: one line per state.
- pivot_table: the same, but piles by two columns at once, laid out as a grid: states down the side, months across the top. This is exactly Excel's PivotTable.
When the AI writes a pivot, you will see these words in its code. Here is what each one means in Excel terms:
Match them Match each pandas word with the Excel PivotTable part that does the same job
Tap an item on the left, then its meaning on the right.
CarefulIn Excel, a number field in Values is summed by default. In pandas,
pivot_tableaverages by default (aggfuncismean). If the AI forgets to ask for a sum, your "total sales" table is full of averages that look perfectly believable.Why?You don't need to write pandas, but knowing these five words lets you read the AI's code and spot a wrong setting in ten seconds.
Log in free to read the rest of this lesson
Every lesson is free. A free account unlocks all of them and saves your progress.
Still to come in this lesson:
- A state × month table, with counts next to sums
- Month-on-month, and the small-base trap
- A GST column check (consistency, not tax advice)
- Reconcile with an Excel or Sheets pivot
- Recap