Notebooks (Jupyter, Google Colab, VS Code notebooks) are where most Python analysis happens. They are also where analysis most often becomes a tangled mess: cells run out of order, variables overwritten, and nobody else can follow it. A few habits fix that.
Structure it like a report
Use markdown cells as headings and short explanations:
- Title and question: what are we trying to find out?
- Setup: imports and settings in the first cell.
- Load data.
- Clean data: with a sentence on each decision.
- Analysis: one section per question.
- Findings: a short summary at the end (and ideally also at the top).
A reader should be able to skim only the markdown and understand the story.
Restart and run all, often
Notebooks remember variables from cells you ran earlier, even if you deleted or changed those cells. Code that works in your session may fail for someone else. Regularly use Restart kernel and run all cells. If it runs top to bottom without errors, the notebook is honest.
Keep cells small and in order
- One step per cell: load, clean, group, plot.
- Avoid going back and editing a cell far above without re-running what follows.
- Do not overwrite important variables (
df = ...five times). Use clear names likeorders_raw,orders_clean,city_summary.
Put settings and paths in one place
import pandas as pd
import seaborn as sns
pd.set_option("display.max_columns", 50)
DATA_PATH = "data/orders.csv"Show results, not walls of output
- Display
.head(), not whole DataFrames. - End a cell with the object you want shown instead of printing everything.
- Remove debugging cells before sharing.
Turn repeated code into functions
If you write the same cleaning code twice, move it into a function near the top, or into a separate .py file you import.
Useful keyboard shortcuts (Jupyter)
| Shortcut | Action |
|---|---|
| Shift + Enter | Run cell, move to next |
| Esc then A / B | Insert cell above / below |
| Esc then M / Y | Change cell to markdown / code |
| Esc then D, D | Delete cell |
| Tab | Autocomplete |
| Shift + Tab | Show a function's help |
Preparing a notebook to share
- Restart and run all, so outputs match the code.
- Add a README explaining the project and how to run it.
- Do not include passwords, API keys or private data.
- Keep charts titled and labelled.
- On GitHub, notebooks render with their outputs, so a clean run doubles as a report.
When to move beyond a notebook
For analysis that runs every week, move stable code into scripts or functions and keep the notebook for exploration and presentation.
Practise
JobPrax practice and live projects run notebook-style in the browser, and finished projects can be pushed to GitHub. For presenting them, read the GitHub portfolio guide.
Practise what you just read
Reading helps; writing the code yourself is what sticks. Start here: