Getting started with JupyterLab

JupyterLab is an interactive development environment that lives in your browser. It combines code execution, data manipulation, and documentation in a single window, which means you stop moving between a terminal, an editor, and a spreadsheet application every time you need to test a hypothesis or explore a dataset.

Why reach for JupyterLab

The appeal comes down to three things working together. First, you can run code in isolated cells, execute a single cell without rerunning everything else, and see results immediately. This matters when you’re iterating and testing a regex, reshaping a dataset, checking if a hypothesis holds. Second, plots and visualisations render inline, so your data and your visual interpretation sit in the same context. Third, markdown cells let you document your reasoning alongside the code that implements it. When you come back to this notebook six months later, you’ll understand what you were testing and why.

Installing JupyterLab

If you already have conda installed, the setup is straightforward:

conda install -y jupyter jupyterlab notebook ipykernel

Run this from within your active Python environment. Once it completes, start the server:

jupyter lab

This opens JupyterLab in your browser. You’re now working with a web interface that communicates with a local Python kernel.

The notebook interface

The notebook is the core document type. Think of it as a cell-based editor where each cell contains either executable code or formatted text. To create a new notebook, click the Python 3 icon under Notebook in the Launcher. You’ll get a blank notebook with a single empty code cell waiting for input.

Code cells execute Python (or other languages, depending on your kernel). Type your code and press Shift+Enter to run it:

print("Hello, JupyterLab!")

The output appears directly below the cell. Markdown cells let you write formatted text, lists, links, and equations using markdown syntax. Use the dropdown in the toolbar to switch cell types, or add new cells with the plus button.

The stateful environment is worth understanding because it catches practitioners off guard. Variables you define in one cell remain available in every cell below it, as long as the kernel hasn’t restarted. If you define x = 1 in cell one, then run cell two which prints x, you’ll get 1. But if you go back and change cell three to x = 2, re-run it, then run cell two again, the output changes. The notebook state depends on execution order, not cell order on the page.

This creates a common pitfall in that, if you execute cells out of sequence, you can end up with state that doesn’t match the notebook’s layout. A cell might reference a variable that hasn’t been defined yet (in reading order) but was defined earlier in time. For this reason, it’s good practice to run cells top-to-bottom and restart the kernel occasionally to verify the notebook works from a clean state.

Working with data

JupyterLab integrates naturally with pandas and matplotlib. Here’s a typical workflow:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

# Create a sample DataFrame
data = pd.DataFrame({
    "column1": np.random.rand(50),
    "column2": np.random.rand(50) * 10
})

# Inspect the data
print(data.head())

Run this cell and you’ll see a formatted table output. In the next cell, create a visualisation:

# Create a scatter plot
plt.scatter(data["column1"], data["column2"])
plt.xlabel("Column 1")
plt.ylabel("Column 2")
plt.title("Scatter Plot")
plt.show()

The plot renders inline. You can adjust axis labels, colours, or plot type in the same cell, re-run it, and see the result immediately. This is where the interactivity pays off because you’re not writing a script, saving it, running it in a separate window, then editing and repeating, you’re iterating in place.

Saving and naming your work

The save button is in the toolbar, or use Ctrl+S. Right-click on the notebook tab or filename in the file browser to rename it. Give your notebooks meaningful names as they’re often shared with others or reviewed later.

Restarting the kernel

The kernel maintains all variable state, imports, and function definitions in memory. If your notebook becomes cluttered with old variables or you encounter unexpected behaviour, restart it from the Kernel menu. You have two options. Restart Kernel preserves your cell outputs but clears all internal state. Alternatively, Restart Kernel and Clear All Outputs removes everything from the notebook.

After restarting, re-run cells from the top to restore the environment. This is useful both for debugging (does the notebook work from a fresh start?) and for clearing out accumulated junk from lengthy exploratory sessions.

Leave a Reply

Your email address will not be published. Required fields are marked *

RELATED

Bayesian spam classification: the dataset

Preparing the SMS Spam Collection dataset for Bayesian classification, covering download, extraction, loading, and cleaning through an adversarial lens.

Spam classification: Naive Bayes filters

How Naive Bayes spam filters work, why the independence assumption makes them exploitable, and how GoodWords attacks broke email filtering…

Metrics for evaluating a model

Learn how accuracy, precision, recall, and F1-score work in practice, where each metrics deceive, and how adversaries exploit the gaps…

Python libraries for AI red teaming

Python Libraries: How scikit-learn and PyTorch work, and why their APIs are the operational foundation for adversarial machine learning.