Skip to content

Jupyter notebook

A Jupyter notebook combines code, explanation and saved outputs. Trace why cell order can differ from kernel state, and what a fresh run actually checks.

A Jupyter notebook is a computational document that combines executable code cells, explanatory text and saved results. In quantitative research, it lets a reader follow a calculation alongside its assumptions and charts. The crucial qualification is that the visible document and the running computation have different histories.
Jupyter Notebook is also the name of an application for editing these documents. A notebook file has the .ipynb extension and uses JSON to store cells, metadata and any saved outputs. Code cells have an execution count; Markdown cells hold the explanation. A saved output records a result from an execution, rather than proving that the current code and inputs still produce it. See the official Notebook guide and file-format specification.

The kernel remembers what ran

The kernel is the process that executes code sent from the notebook interface. A Python kernel retains names and objects between cell executions. Other kernels support other languages; the notebook format is not restricted to Python. The Jupyter kernel documentation explains this separation between the interface and the language process.
Consider three cells, displayed in order A, B, C. Here x is a hypothetical USD notional and y is an amount calculated at 2% of that notional.
Cell A — establish the input:
x = 100
Cell B — calculate the amount:
y = x * 0.02 print(y) # 2.0
Cell C — change the input and inspect the names:
x = 200 print(x, y) # 200 2.0
After A, B and C run, x is 200 but y remains 2.0. Python evaluated the multiplication when B ran; the assignment did not create a spreadsheet-style formula that tracks later changes to x. This follows Python's assignment semantics.

Now run B again:

y = x * 0.02 print(y) # 4.0
The kernel now holds x = 200 and y = 4.0. B still appears above C in the document. C's previously printed 200 2.0 also remains an old output until C runs again. A reader can therefore see results from different moments on the same page. Execution counts help identify the most recent run of each cell, but are not a complete log of edits, deleted cells or earlier executions.
Cells appear A, B, C, while execution A, B, C, B leaves successive kernel states: x 100 with y unset; x 100 and y 2; x 200 and y 2; x 200 and y 4. Amounts are hypothetical USD.
Cells appear A, B, C, while execution A, B, C, B leaves successive kernel states: x 100 with y unset; x 100 and y 2; x 200 and y 2; x 200 and y 4. Amounts are hypothetical USD.
Original Python scenario. The document order stays A, B, C; rerunning B changes the computed amount from USD 2 to USD 4 without moving a cell.

A fresh run is a test, not a repair

Restart the kernel and run all cells from top to bottom before sharing a result. In this example, a fresh A → B → C run ends at x = 200, y = 2.0 again. Restarting removes the manually accumulated state; it does not rearrange the calculation to match the researcher's intention. If the intended calculation uses USD 200, establish that input before B and remove the contradictory reassignment.

For research reproducibility, retain the input data snapshot, code revision, configuration, interpreter and dependency versions, and any random seeds alongside the notebook. A clean run tests whether this execution can succeed from fresh kernel state. It cannot recover missing files or guarantee the same numerical results across different environments.

Keep exploration and commentary in the notebook; put calculations that must be reused or tested into importable functions. The SelfMadeQuant lesson Jupyter and Scripts develops that workflow; its public page is a preview and the full lesson requires membership.

Sources

Last updated
  • python
  • research workflow
  • notebooks
  • reproducibility
← Back to the glossaryBack to top ↑