Get your API key

Lesson 3 of 5

Pivots and comparisons you can trust

State and month pivots in plain words, the % change trap, a GST column consistency check, and reconciling with an Excel pivot.

8 min Log in to open
One step at a time, like flipping pages.

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

  1. 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.

    Careful

    In Excel, a number field in Values is summed by default. In pandas, pivot_table averages by default (aggfunc is mean). 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:

  1. A state × month table, with counts next to sums
  2. Month-on-month, and the small-base trap
  3. A GST column check (consistency, not tax advice)
  4. Reconcile with an Excel or Sheets pivot
  5. Recap