Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Setting Up Your Data Toolkit  ›  Capstone Project

Notebooks: JupyterLab, Colab and VS Code

JupyterLab 12 minA notebook sends cells to a kernel that keeps variables in memory, so results depend on the order cells were run rather than the order they appear.

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 automatically

Run 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 .ipynb files 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.

A notebook that liesStep 1 of 4
  1. Cell A, run first

    price = 250 is 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.

quick drill

What keeps variables alive between notebook cells?

quick drill

Cells show [5] above [2] on the page. What does that tell you?

quick drill

Which option needs no installation at all to start analysing a small CSV?

quick drill

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.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainThe notebook that works only for you

Your notebook runs perfectly for you, but a colleague who opens it gets a NameError in cell 4. Explain the most likely cause and how you would check and fix it before sharing.