1.4.9 · D1Python & Scientific Computing

Foundations — Jupyter notebooks workflow

1,852 words8 min readBack to topic

Before you can trust a single sentence of the parent note, you need a picture for each word it throws at you. Below, every term is built from nothing — plain words first, then a picture, then why the topic can't live without it. Read top to bottom; each one leans on the one above it.


1. The Kernel — the hidden brain

Plain words. Imagine a calculator that never forgets. You press "5 + 5", it shows 10, and — crucially — it keeps that 10 around in case you want it later. The kernel is that calculator, but for full Python.

The picture. Look at the figure: on the left is the notebook (what you see in the browser — boxes and text). On the right is the kernel (a box you don't see). An arrow carries your code across to the kernel; another arrow carries the answer back.

Figure — Jupyter notebooks workflow

Why the topic needs it. The parent note says "restarting the kernel clears everything." That sentence is meaningless until you know the kernel is a separate memory. Kill it, and the memory is wiped — the notebook paper stays, but the brain forgets.


2. A Cell — one box you can run

Plain words. Instead of one giant page of code, a notebook chops the work into boxes. You run box 1, look, run box 2, look. Each box is a cell.

The picture. In the figure, stacked boxes are cells. The highlighted one is selected; when you press a run key, only that box's code travels to the kernel.

Why the topic needs it. The whole advantage over a plain script — "test one line without re-running everything" — is exactly the power to run one cell at a time. No cells, no notebook.


3. Namespace — the kernel's memory as a labelled shelf

This is the concept the parent note leans on hardest, so we build it slowly with a picture.

Plain words. When you write x = 5, you are telling the kernel: "make a box labelled x, put 5 inside, keep it on the shelf." Later, y = x * 2 means: "go find the box labelled x, read its contents, double it, store the result in a new box y."

The picture. In the figure, the shelf starts empty. After cell 1 runs x = 5, a box labelled x holding 5 appears. After cell 2 runs y = x * 2, the kernel looks up x (finds 5), computes , and adds a box y holding 10.

Figure — Jupyter notebooks workflow

Why the topic needs it. Persistent memory between cells, out-of-order execution, and restart clears everything are all really one fact: cells share one namespace that lives in the kernel. Restart the kernel → build a brand-new, empty shelf.


4. The Execution Counter In [n]

Plain words. Think of it like a ticket dispenser at a bakery. Every time you run a cell, the kernel tears off the next number and staples it to that cell. The number is not the cell's position on the page — it's the order in which you actually ran things.

Why the topic needs it. If you see In [5] sitting above In [12] on the page, the tags reveal you ran the page out of order — the single biggest source of "works for me, breaks for you" bugs (see 4.1.05-Debugging-strategies). The counter is your evidence.


5. "Last expression auto-displays" — what counts as output

Plain words. Jupyter has a quiet convenience rule: after a cell runs, it automatically prints the value of the very last expression — but only the last one. Everything above it runs silently.

The picture. In the figure, three lines run inside one cell. The first two produce values that vanish (no tag, no print). Only the last line's value floats down into the output area below the cell.

Figure — Jupyter notebooks workflow

Why the topic needs it. Every "Why this step?" in the parent's examples hinges on this rule. Miss it and you can't predict what a cell will show you.


6. The .ipynb file — paper that remembers outputs, not order

Plain words. When you save, the notebook writes down what each cell contained and what it last printed. It does not write down the kernel's shelf of variables — that lives only in the running kernel and dies when the kernel stops.

Why the topic needs it. This is the exact trap in the parent's final mistake: the file saved beautiful outputs, but a fresh reader's kernel starts with an empty shelf and runs cells top-to-bottom. A cell that secretly relied on a variable you made later now hits a NameError. The cure — "Restart & Run All" — throws away the shelf and rebuilds it in page order, proving the notebook truly reproduces itself.


How these foundations feed the topic

Kernel the hidden brain

Namespace the labelled shelf

Cell one runnable box

Run a cell send code to kernel

Persistent memory across cells

Execution counter In n

Out of order execution risk

Last expression auto displays

ipynb saves outputs not order

Reproducible Jupyter workflow

Read it as a supply chain: the kernel holds a namespace; running a cell writes to that namespace and bumps the counter; because memory persists but the file only saves outputs, you get both the power (fast, out-of-order exploration) and the danger (irreproducible order) that the whole workflow is about.


Where these skills come from and go next

  • You launch notebooks inside a clean virtual environment so the kernel's Python has exactly the libraries you expect.
  • The variables on your shelf are usually NumPy arrays and Pandas DataFrames — like data[['ad_spend', 'season']] in the parent's model.
  • The plots that auto-display come from Matplotlib.
  • This entire cell-by-cell rhythm is the engine of exploratory data analysis, and cell isolation is a core debugging strategy.
  • Full topic: Jupyter notebooks workflow.

Equipment checklist

Recall

What is the kernel, in one sentence? ::: The hidden, separate Python program that runs your code and remembers every variable — kill it and the memory is wiped. What is a namespace? ::: The kernel's shelf of labelled boxes: each name (label) points to a value; cells all share one shelf. Why can y = x * 2 in cell 2 use the x from cell 1? ::: Because both cells write to and read from the same namespace living in the kernel — memory persists between cells. What does the number in In [n] actually tell you? ::: The order in which cells were run (not their position on the page); = previous highest + 1. If In [5] appears above In [12], what happened? ::: The notebook was run out of order — a warning sign for reproducibility. Which line of a cell auto-displays its value? ::: Only the last expression; earlier values run silently unless you wrap them in display(...) or print(...). What does a saved .ipynb store — and not store? ::: It stores each cell's code and last output; it does not store the live namespace or the run order. Why does "Restart & Run All" catch the "works for me" bug? ::: It empties the shelf and re-runs cells top-to-bottom, exposing any cell that secretly depended on a variable made later. What is the difference between an expression and a statement? ::: An expression evaluates to a value (can be displayed); a statement performs an action (like assignment) and has no value to show.