Skip to main content

Notebooks, kernels and editors

What the pieces are, which programs open them, and when to use which.

Interfacewhere you read and typeJupyter Notebook, JupyterLab, VS Code, Colab
→
Notebookthe fileS01_pandas_I.ipynb
→
Kernelruns the codePython, R (DMA), Stata, MATLAB...
→
Environmentthe packages it seespandas, duckdb, tidyverse...

The notebook

  • What it is: one file, with extension .ipynb, that keeps text, code and results together.
  • Cells: a notebook is a list of cells. A code cell runs and shows its output below. A Markdown cell is text, with headings and formulas.
  • Run a cell: Shift+Enter.
  • Run order: the kernel remembers what you ran, in the order you ran it, which can differ from the order on the screen. A cell that you deleted can still be in memory.
  • Before you trust a result: Kernel, then Restart Kernel and Run All Cells. A notebook that runs from top to bottom is reproducible.

The kernel

  • What it is: the process that runs the code of the notebook and keeps its variables in memory.
  • One notebook, one kernel. Every code cell is in the language of that kernel.
  • Choose it: Kernel, then Change kernel. The name of the current one is at the top right of the notebook.
  • In this course: two kernels, Python and R (DMA), installed in the setup.
  • How a kernel is registered, listed and removed: How the setup works.

The environment

  • What it is: the set of packages, with their versions, that a kernel can use.
  • The course environment: the one of the setup, DMA/.venv with uv or dma with Anaconda. Same environment, same results on every laptop.
  • How it is built (pip, conda, uv): How the setup works.
  • Typical failure: No module named ... means that Jupyter started from another environment. Close it and start it from DMA.
  • Working directory: the folder from which relative paths such as data/wdi_panel.csv are read. Jupyter sets it to the folder of the notebook.

Where you open notebooks

Program What it is Use it when
Jupyter Notebook One notebook per browser tab In class, and whenever you want the simplest screen
JupyterLab Several notebooks, files and a terminal in one browser window You work with several files at once
Google Colab Notebooks on Google’s servers, with Python, R or Julia You cannot install (Working in Colab)

Jupyter Notebook and JupyterLab come with the course installation and open the same files with the same kernels.

Editors and IDEs

A general editor writes code in any language. Extensions add each language, the notebooks and the choice of kernel.

Program What it is Use it when
VS Code The most used general editor. Extensions: Python, Jupyter, R, Julia You want notebooks and scripts in one place
Positron Built on VS Code by the makers of RStudio, for Python and R You work in both and like to see your data and plots
Cursor, Antigravity Built on VS Code, with an AI assistant You already use them: they open the same files
RStudio The IDE of R: .R, .Rmd, .qmd You work only in R
Stata Its own window: commands, results, data and the Do-file Editor You work in Stata, with .do files
MATLAB Its own IDE: editor, command window and workspace You work in MATLAB, with .m files

In VS Code and the editors built on it, open the DMA folder and choose the course kernel: DMA/.venv with uv, or the environment dma with Anaconda.

Kernels for other languages

Language In a notebook Needs
Python The Python kernel Installed in the setup
R The kernel R (DMA) Installed in the setup
SQL From Python with duckdb, on pandas tables and on files, as in the sessions Installed in the setup
Stata Kernel nbstata, or stata_kernel for older versions Stata with a licence; nbstata needs Stata 17 or later
Stata inside Python pystata, which comes with Stata: cells that start with %%stata Stata 17 or later, with a licence
MATLAB Kernel jupyter-matlab-proxy MATLAB R2020b or later, with a licence
Julia Kernel IJulia. Julia also runs in VS Code with its extension Julia (free)

Once installed, each one appears in Kernel, then Change kernel, next to Python and R (DMA). We install and support only the first three.

Scripts and notebooks

  • A script is a plain text file with code: analysis.py, analysis.R, analysis.do. It runs from top to bottom, from a terminal or from an editor.
  • Notebooks are for exploring and explaining. Scripts are for code that must be rerun the same way.
  • Later in the course we turn a notebook into a script.
uv run python analysis.py
Rscript analysis.R

What we use in class

Jupyter Notebook or JupyterLab on your laptop. Any program above is fine for practice. The tests are on paper, without a computer and without AI, so practise in a way that prepares you for that.