Notebooks: JupyterLab, Colab and VS Code
Data analysis is a conversation with your data: load it, look, ask a question, look again. Running a whole script from the top for every small question is slow. A notebook lets you run one piece at a time and keeps the results on screen next to the code that made them.
The rule
A notebook remembers what you ran, in the order you ran it — not the order shown.
A notebook is a page of cells. A code cell holds Python; a markdown cell holds notes. Behind the page sits a kernel, a running Python process that keeps every variable alive between cells.
# Cell 1
import pandas as pd
sales = pd.read_csv("sales.csv")
# Cell 2
sales.head() # the last line of a cell is displayed automaticallyRun Cell 1 once, then run Cell 2 as many times as you like. sales stays in memory, so you never reload the file just to look again.
Three common places to run notebooks:
- JupyterLab: runs on your own machine, opened in the browser. Uses the packages in whichever environment you start it from.
- Google Colab: a hosted notebook in the browser. Nothing to install, pandas and NumPy come ready, and files live in the cloud session, which resets after a while.
- VS Code: opens
.ipynbfiles inside the editor. You pick the kernel (for example your project's.venv) from a menu.
The shortcut
When a notebook behaves strangely, ask "What has the kernel actually run?" The small number beside each cell, like [7], tells you the order of execution. If a variable seems wrong, the fix is usually Restart kernel and run all, which replays the page from top to bottom.
Cell A, run first
price = 250is run, and the counter shows[1].
The trap is deleting a cell that defined a variable. The variable stays in the kernel, so everything still works today, but the notebook breaks for anyone who opens it fresh. Restart and run all before you share.
Drills
Answer fast — trust the rule.
What keeps variables alive between notebook cells?
Cells show [5] above [2] on the page. What does that tell you?
Which option needs no installation at all to start analysing a small CSV?
You deleted the cell that loaded sales, yet sales.head() still works. Why?
Remember
- A notebook remembers what you ran, in the order you ran it — not the order shown.
- Read the
[n]counters; when in doubt, restart the kernel and run all. - JupyterLab is local, Colab is hosted, VS Code opens notebooks in the editor with a kernel you choose.
