A data lab: Python, pandas and Jupyter on your own computer

Install Python, create an isolated environment, add pandas, NumPy and Jupyter, and open a notebook so you can load a CSV file, clean it and answer questions about it with the same tools professional analysts use.

  • Time: 30 to 45 minutes
  • Cost: free software, your own computer

What you need

The browser labs in this course run real Python and real pandas, so you can finish every case without installing anything. Setting up the same tools on your own computer is still worth doing: it lets you work on your own files, keep your notebooks and carry on after the course.

You need only three things, and all of them are free:

  • Python 3.10 or newer from python.org. On Windows, tick “Add Python to PATH” in the installer.
  • pandas and NumPy, the table and number libraries the course uses.
  • Jupyter, which gives you notebooks: pages where you write a few lines of code, run them, and see the result (a table or a chart) directly underneath.

Allow about 1 GB of disk space and a few minutes of download time.

Set it up

  1. Open a terminal (PowerShell on Windows, Terminal on macOS, any shell on Linux) and check Python:
python --version
  1. Make a folder for your work and create a virtual environment, a private set of libraries for this project so that nothing you install can break another project:
mkdir data-practice
cd data-practice
python -m venv .venv
  1. Switch it on. On Windows PowerShell use .venv\Scripts\Activate.ps1; on macOS and Linux use source .venv/bin/activate. Your prompt now starts with (.venv).

  2. Install the libraries:

pip install pandas numpy matplotlib jupyterlab
  1. Start Jupyter and create a notebook:
jupyter lab

A browser tab opens. Choose Python 3 (ipykernel) under Notebook. If you prefer Visual Studio Code, install its Python and Jupyter extensions, open the folder, create a file ending in .ipynb and choose the .venv interpreter when asked.

Check that it works

In the first notebook cell, type this and press Shift+Enter:

import pandas as pd
df = pd.DataFrame({"city": ["Lagos", "Kano", "Lagos"], "minutes": [42, 65, 51]})
print(df.groupby("city")["minutes"].mean())

You should see Kano at 65.0 and Lagos at 46.5. Now save a small CSV file (copy the first lines of any export you are allowed to use) into your folder and load it with pd.read_csv("yourfile.csv"). If df.head() shows a table, your lab works.

For every case in the course you can copy the generated file out of the lab page, save it as a .csv next to your notebook and repeat the work locally to compare the results.

Practise safely

  • Use public or invented data while you learn. Good free sources are government open-data portals, the datasets in your own organisation that you are authorised to use, and files you generate yourself.
  • Never put real customer or staff records in a notebook that you upload to the internet. A shared notebook keeps its output, including any table you displayed.
  • Keep the raw file untouched and do all cleaning in code. Write the result to a new file, so you can always start again.
  • Do not install packages from sources you do not trust, and do not run a notebook someone sends you without reading it first, because a notebook can run any code.
  • Use one virtual environment per project and record the versions with pip freeze > requirements.txt so you can rebuild it later.

Go further

  • Draw your first chart with df["minutes"].plot.hist() and matplotlib, and label the axes.
  • Keep your notebooks in a Git repository, which the developer workstation guide shows how to set up, and commit after each question you answer.
  • Try the same analysis in a spreadsheet and in SQL, and compare the effort and the answers. Knowing three ways to ask a question makes you hard to fool.
  • Move from pandas to scikit-learn and a simple model when you reach the machine learning course.
  • Join a free community such as a local data meetup or an online forum, and practise explaining your results to someone who did not see your notebook.

Courses that use this lab

Other lab guides

Software changes quickly. Menu names and version numbers may differ a little from what you see; the ideas and the check at the end of each section stay the same. Always download from the project's own website, and read the licence terms for your situation.