TOPIC 22/2313 MINNOT STARTED

Scripting for analysts: reading Python and notebooks

Learn to read a short Python script and a notebook the way an analyst needs to: follow the lines, question what they count, spot hidden state, and check a number by a second route.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: A recipe card. A recipe card lists the steps in the right order. Take out the flour. Add two eggs. Stir. Bake. You read it from the top to the bottom, and each line does one small thing. If you can read the card, you can tell whether the cake will come out right, even if you cannot bake it yourself.

A Python script is a recipe for a computer. Python is a popular programming language, a way to give a computer steps in writing. A is a recipe card with room for notes. It mixes your notes, small pieces of code and the results of running them, one piece at a time.

Sam is the , or (BA), for Daily List, a to-do app. Leo, the developer, shares a notebook with four lines. It loads the task export, groups the tasks by status and counts each group. Nina, the product owner, asks, "Can we trust the number?" Sam does not need to write the notebook. He needs to read it.

Two more ideas help. A DataFrame is a table of rows and columns held in memory, which the script can filter, group and count. is a trap: values kept in memory from cells that ran earlier or in another order.

The picture has a limit. A recipe is the same every time you read it. A notebook can give a different result if its pieces were run in a different order.

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the work.

THE REAL JOB The picture helps a newcomer remember to read a script line by line, ask what each step keeps or drops, and test it from a clean start.

  1. What comes in?
  2. What is kept or dropped?
  3. What is grouped and counted?
  4. Run it fresh from the top
  5. Check the number a second way
Reading a notebook

HOW THE PICTURE MAPS

How each part of the picture matches the work
In the pictureIn the work
The recipe cardA script or notebook
One line of the recipeOne step on the table
The mixing bowlThe table in memory
A bowl with last night's leftoversHidden notebook state
Washing the bowl and cooking again from step oneRestart and run all

WHERE THIS PICTURE STOPS

  • A recipe reads the same every time, but a notebook can give a different result if pieces ran in a different order.
  • A cook can taste as they go, but a number does not tell you if it is wrong.
  • A recipe has one cook, but a notebook is often edited by several people.

HOOK

Read down, count what is kept, run it fresh.

REMEMBER IT THIS WAY

A chunk: a long list grouped so it is easier to hold.

Read the notebook from the top: load, group, count. Ask what each line does.

What each part of the trick stands for
In the trickWhat it stands for
loadloads the task export
groupgroups the tasks by status
countcounts each group

TELL A FRIEND

A notebook is a recipe card for data. Read it from the top, ask what comes in, what is kept and what is counted, and test it by restarting and running all from the start.

OFTEN MIXED UP WITH SQL for BAs: SELECT and WHERE. That topic shows how to ask a database for rows and counts. This one shows the same ideas written as Python lines in a notebook.

Sources & standards — 3 sources
  1. Implementation-specific

    Group by: split-apply-combine (pandas user guide) ↗ — pandas project · GroupBy dropna section and examples: missing keys excluded by default; selected user-guide section read 7 November 2026, case executed with pandas 2.2.3.

    Official project documentation. Describes grouping a table by a column and counting each group; count skips missing values. Search excerpt only. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Implementation-specific

    Comparison with SQL (pandas documentation) ↗ — pandas project · GROUP BY count versus size and missing values; selected comparison sections read 7 November 2026, missing-key/id counterexample executed with pandas 2.2.3 and SQLite.

    Official project documentation. Shows pandas steps beside the matching SQL, and notes that size is the closer match to a SQL row count while count skips missing values. Search excerpt only. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  3. Implementation-specificnbformat4

    The Jupyter Notebook format ↗ — Project Jupyter · Notebook structure; cell types; code cells, execution_count and outputs; nbformat 4 selected sections read 7 November 2026.

    Selected current nbformat 4 document/code-cell sections read. Source, saved outputs and execution_count describe saved state, not a guarantee of reproducibility. · Checked 2026-11-07

    Selected primary-source sections read for the BA Analytics audit. This record does not certify unrelated chapters or product features. No reuse permission for publisher images is inferred.

PRACTISE AND KEEP

Sources for this topic — 10 sources
  1. Market practice

    Group by: split-apply-combine (pandas user guide) ↗ — pandas project · Group by: split-apply-combine (pandas user guide): grouping a table by a column and counting each group; count skips missing values (search excerpt, page not opened)

    Official project documentation. Describes grouping a table by a column and counting each group; count skips missing values. Search excerpt only. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  2. Market practice

    Comparison with SQL (pandas documentation) ↗ — pandas project · Comparison with SQL (pandas documentation): pandas steps shown beside the matching SQL; size is the closer match to a SQL row count, while count skips missing values (search excerpt, page not opened)

    Official project documentation. Shows pandas steps beside the matching SQL, and notes that size is the closer match to a SQL row count while count skips missing values. Search excerpt only. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  3. Market practice

    The Jupyter Notebook format (IPython documentation) ↗ — Project Jupyter · The Jupyter Notebook format (IPython documentation): a notebook is a sequence of cells; code cells hold source and outputs; the file is saved as JSON (search excerpt, page not opened)

    Format reference for an older release. Says a notebook is a sequence of cells, code cells hold source and outputs, and the file is saved as JSON. Search excerpt only. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  4. Market practice

    Fine-grained lineage for safer notebook interactions (research paper on arXiv) ↗ — arXiv · Fine-grained lineage for safer notebook interactions (research paper on arXiv): hidden state: a cell depends on code from cells that ran in a different order (search excerpt, page not opened)

    Research paper. Describes hidden state in notebooks, where a cell depends on code from other cells run in a different order. Search excerpt only. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  5. Market practice

    Data Structures (Python tutorial) ↗ — Python · Data Structures (Python tutorial): lists, dictionaries and ways to loop over them (registry source; search excerpt, page not opened)

    Describes lists, sets without duplicates, dictionaries of key-value pairs with unique keys, and that lists cannot be dictionary keys. Practitioner or vendor guidance, not a standard unless stated. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  6. Market practice

    More Control Flow Tools (Python tutorial) ↗ — Python Software Foundation · More Control Flow Tools (Python tutorial): the for statement loops over the items of a sequence in order (registry source; search excerpt, page not opened)

    Per the search excerpt (from copies of the tutorial text), an if statement can have zero or more elif parts and an optional else part, and a for statement goes over the items of a sequence in order. The live Python 3 page was not returned. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  7. Simplified educational illustration

    Payments Signal editorial teaching models — Payments Signal

    This site's own simplified teaching models. · Checked 2026-07-12

    What this simplifies: Daily List, Sam, Nina, Leo, Tom, Mei and Lily are invented, and the tiny script and its counts are made up for teaching. Python and pandas have far more features than shown. The pages were search excerpts, and none was opened. The pandas pages describe their own versions, so check the version a team uses.

    Used wherever diagrams, scenarios, figures, or example values are didactic constructions rather than sourced facts; every such use carries a simplifications disclosure. All people, companies, banks, and list entries in examples are fictional.

  8. Implementation-specific

    Group by: split-apply-combine (pandas user guide) ↗ — pandas project · GroupBy dropna section and examples: missing keys excluded by default; selected user-guide section read 7 November 2026, case executed with pandas 2.2.3.

    Official project documentation. Describes grouping a table by a column and counting each group; count skips missing values. Search excerpt only. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  9. Implementation-specific

    Comparison with SQL (pandas documentation) ↗ — pandas project · GROUP BY count versus size and missing values; selected comparison sections read 7 November 2026, missing-key/id counterexample executed with pandas 2.2.3 and SQLite.

    Official project documentation. Shows pandas steps beside the matching SQL, and notes that size is the closer match to a SQL row count while count skips missing values. Search excerpt only. · Checked 2026-10-18

    Found through a web search; the page was not opened (search excerpt, page not opened). Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.

  10. Implementation-specificnbformat4

    The Jupyter Notebook format ↗ — Project Jupyter · Notebook structure; cell types; code cells, execution_count and outputs; nbformat 4 selected sections read 7 November 2026.

    Selected current nbformat 4 document/code-cell sections read. Source, saved outputs and execution_count describe saved state, not a guarantee of reproducibility. · Checked 2026-11-07

    Selected primary-source sections read for the BA Analytics audit. This record does not certify unrelated chapters or product features. No reuse permission for publisher images is inferred.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.