Python for Data Science · PGE 5 · PSB

Set up Python before Session 1

About 30 minutes, most of it waiting for the download. Do it at home on a good connection, not in the classroom.

What you installAnaconda: Python, Jupyter and every library we use
What you need~5 GB free disk space, admin rights on your laptop
If it failsGoogle Colab in your browser, with nothing to install
My computer is a

1. Install Anaconda

Anaconda bundles Python with Pandas, Matplotlib, Seaborn, SciPy, statsmodels and Jupyter, the tools for all four sessions.

  1. Download the installer

    Go to anaconda.com/download. The site asks for an email address; you can use Skip registration below the form.

    Choose the Windows 64-Bit Graphical Installer (the .exe file).

    Choose the Graphical Installer (the .pkg file) that matches your chip:

    • Click the Apple menu (top left) →About This Mac.
    • Chip: Apple M1, M2, M3, M4… → download the Apple Silicon version.
    • Processor: Intel… → download the Intel version.
  2. Run the installer

    Double-click the .exe file and accept the defaults, with two things to check:

    • Install for Just Me (recommended).
    • Leave “Add Anaconda to my PATH” unticked. This is the default.
    Accents or spaces in your Windows user name? (e.g. C:\Users\Hélène Dupont.) The installer may refuse the default location. Install to C:\anaconda3 instead.

    Double-click the .pkg file and follow the steps. Choose Install for me only and accept the defaults. Enter your Mac password when asked.

    The installation takes 5–15 minutes. Wait until it says it has finished.

  3. Open a terminal that knows about Anaconda

    Open the Start menu and search for Anaconda Prompt. Use this, not the ordinary Command Prompt or PowerShell. The line should start with (base).

    Open Terminal (⌘ + Space, type “Terminal”). If it was already open, close it and open a new one. The line should start with (base).

    Type this and press Enter:

    python --version
    Python 3.13.5

    Any version from 3.10 up is fine.

2. Set up the course folder

Each session comes as a notebook plus the dataset. Keep them in one folder with this layout, because the notebooks look for the data at data/raw/.

  1. Create the folder and unzip the course pack

    Download the course pack from the course platform and unzip it to a place you can find, such as your Documents folder. You should get:

    PGE5-Python/ ├── session1.ipynb └── data/ └── raw/ └── default of credit card clients.xls
    Unzip first. Windows lets you open files inside a zip without extracting them. Jupyter cannot see those files. Right-click the zip → Extract All.
    Avoid iCloud-synced folders if “Desktop & Documents” sync is on and your disk is nearly full: files may be offloaded and fail to open. A folder in your home directory is safest.
  2. Start Jupyter from the course folder

    In the Anaconda PromptTerminal, move into the folder, then start JupyterLab:

    cd %USERPROFILE%\Documents\PGE5-Python
    jupyter lab
    cd ~/Documents/PGE5-Python
    jupyter lab

    Your browser opens JupyterLab. Keep the terminal window open: closing it stops Jupyter.

    Prefer clicking? Open Anaconda Navigator, launch JupyterLab, and browse to the PGE5-Python folder in the left panel.

3. Check that everything works

In JupyterLab, click File → New → Notebook (choose the Python 3 kernel), save it inside PGE5-Python, paste this into the first cell and press Shift + Enter.

import pandas as pd, matplotlib, seaborn, scipy, statsmodels
print("pandas", pd.__version__)

df = pd.read_excel("data/raw/default of credit card clients.xls", header=1)
print(df.shape)
pandas 2.2.3 (30000, 25)
You see (30000, 25)? You are ready for Session 1. Version numbers may differ from the ones shown here.

If you get an error instead, find it below.

If something goes wrong

Read the last line of the error message first. It usually names the problem.

ImportError: Missing optional dependency 'xlrd'

The old .xls Excel format needs one extra package. Run this in a notebook cell, then restart the kernel (Kernel → Restart Kernel) and run your cell again:

%pip install xlrd
FileNotFoundError: No such file or directory

Jupyter is running from a different folder than the one holding data/. Check where you are:

import os
print(os.getcwd())
print(os.listdir())

The list should include data. If it doesn't, save your notebook inside PGE5-Python (next to session1.ipynb), or restart Jupyter from that folder as in step 2.

'jupyter' or 'python' is not recognized as an internal or external command

You are in the ordinary Command Prompt or PowerShell. Close it and open Anaconda Prompt from the Start menu.

command not found: jupyter (or: conda)

Close Terminal completely (⌘ + Q) and open it again. If the line still does not start with (base), run the command below, then reopen Terminal:

~/anaconda3/bin/conda init zsh
ModuleNotFoundError: No module named 'pandas' (or seaborn, statsmodels…)

The notebook is using a Python other than Anaconda's. This happens most often in VS Code or PyCharm. For this course, start Jupyter from the Anaconda PromptTerminal as in step 2. If you want to stay in your editor, run %pip install pandas seaborn statsmodels xlrd in a cell.

“Anaconda can’t be opened” or the installer is blocked

Open System Settings → Privacy & Security, scroll down, and click Open Anyway next to the Anaconda message.

The installer stops, or complains about the install path

Your user folder contains spaces or accented characters. Run the installer again and change the destination to C:\anaconda3. If your laptop is managed by an employer, you may lack admin rights; use Colab (below) and tell me before the session.

My laptop is old, too full, or a Chromebook / tablet

Use Google Colab (next section). It runs in the browser and gives the same results.

Plan B: Google Colab

Nothing to install, only a Google account. Use it if the installation fails or on the day your laptop misbehaves. Files you upload are deleted when the session ends, so download your notebook before closing the tab.

  1. Open the notebook

    Go to colab.research.google.com, choose File → Upload notebook and select session1.ipynb from the course pack.

  2. Recreate the data folder and upload the file

    Run this in the first cell:

    !mkdir -p data/raw
    %pip install -q xlrd

    Click the folder icon in the left sidebar. Open data → raw, hover over raw, click the ⋮ menu → Upload, and pick default of credit card clients.xls.

  3. Run the check from section 3

    You should see (30000, 25). The paths in the course notebooks now work unchanged.

    Before you close the tab: File → Download → Download .ipynb.

Before Session 1

Tick these off. Your ticks are saved in this browser only.

0 of 4 done