Notebook Hygiene: Making Yours Rerunnable
A research notebook that only works because of cells run out of order, hidden state, or a stale kernel isn't reproducible — a few habits keep it honest and rerunnable from a clean start.
A Jupyter notebook lets you run cells in any order, redefine variables halfway through, and delete a cell without erasing the variables it created. That flexibility is exactly what makes notebooks dangerous for research: it's easy to end up with a notebook that produces the "right" result only because of the specific, undocumented sequence in which cells happened to be run — a sequence nobody, including the author a week later, can reconstruct.
Notebook hygiene is the discipline of keeping a notebook honest: it means the notebook produces the same output when run top-to-bottom from a fresh kernel as it did when you were actively editing it. Practical habits include restarting the kernel and running all cells before treating a result as final; avoiding global mutable state that later cells silently depend on; keeping expensive computations (like loading a large dataset) in early cells so re-running doesn't require redoing hours of work; and moving code that's stabilized into a proper module or script rather than leaving it to live only inside notebook cells.
Worked example. A researcher computes a Sharpe ratio in cell 12, then goes back to cell 4 to widen the date range, forgetting that cell 9 already cached an intermediate dataframe under the old range. Every cell after 9 that reuses that dataframe silently uses stale data — the notebook still runs and produces numbers, but they're wrong, and only a full restart-and-run-all would have caught it.
A notebook that hasn't been run top-to-bottom from a fresh kernel is not yet a verified result — "restart and run all" before trusting or sharing any number is the single habit that catches the most reproducibility failures in research code.
Further reading
- Common practice guidance from research engineering teams