Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 64 ยท Getting Started

Installing pandas and Using Jupyter

Set up pandas on your own computer: create a virtual environment, install pandas with pip or uv, start JupyterLab, and learn how notebook cells and kernels work.

The examples in this course run in your browser, which is perfect for learning. Real projects, however, live on your own computer: your files are there, your data is there, and you want your own tools. This lesson walks you through a clean, repeatable setup: a virtual environment, a pandas installation, and Jupyter, the notebook interface most analysts use every day.

Nothing here is hard, but the order of the steps matters. A little care now saves you from the classic "it worked yesterday" problems later.

What you need

pandas 3 needs a recent Python (3.11 or newer). Check what you have by opening a terminal (Terminal on macOS and Linux, PowerShell on Windows) and typing:

Terminal
python --version

On some systems the command is python3. If the version is older than 3.11, or Python is missing, install the current release from python.org, or use a tool such as uv or Miniconda that can install Python for you.

Step 1: make a project folder and a virtual environment

A virtual environment is a private folder that holds one project's Python packages. Without it, every project shares the same global packages, and upgrading pandas for one project can break another. Make one environment per project:

Terminal
mkdir sales-analysis
cd sales-analysis
python -m venv .venv

Now activate it, so that python and pip refer to the private copy:

Terminal
# macOS and Linux
source .venv/bin/activate

# Windows PowerShell
.venv\Scripts\Activate.ps1

Your prompt usually gains a (.venv) prefix. Whenever you open a new terminal for this project, activate the environment again.

Tip: If you use the uv tool, the same setup is uv venv followed by uv pip install pandas. It is much faster than plain pip and produces the same result.

Step 2: install pandas

With the environment active, install pandas using pip:

Terminal
pip install pandas

pip also installs NumPy, which pandas needs. A few optional packages unlock extra features. You install them only when you need them:

Package Unlocks
openpyxl Reading and writing .xlsx Excel files
pyarrow Parquet files and Arrow-backed data types
matplotlib The .plot() methods and styled tables
scipy Spearman correlation, interpolation and more
sqlalchemy read_sql with databases other than SQLite

For example: pip install openpyxl matplotlib pyarrow.

To record exactly what your project uses, save the list to a file and share it with teammates:

Terminal
pip freeze > requirements.txt
pip install -r requirements.txt   # on another machine

Step 3: check the installation

Start Python and ask pandas for its version. The example below does the same thing, so you can see what a working installation prints. It also shows which Python and NumPy versions are in use:

Python Check your versions

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

When you ask for help online or file a bug report, include these three version numbers. pd.show_versions() prints a much longer report with every optional package.

Step 4: install and start Jupyter

Jupyter is a web-based notebook. You write code in cells, run a cell with Shift+Enter and see the output directly under it. The last expression of a cell is displayed automatically, and DataFrames appear as neat HTML tables. That immediate feedback is why notebooks are so popular for exploring data.

Terminal
pip install jupyterlab
jupyter lab

The second command starts a local server and opens JupyterLab in your browser (usually at http://localhost:8888). Click Python 3 under "Notebook" to create a file ending in .ipynb.

Three ideas explain almost everything about notebooks:

  • Cell: a block of code (or Markdown text). Cells can be run in any order, and they can be run more than once.
  • Kernel: the background Python process that remembers all your variables. When you run a cell, the kernel executes it. Restarting the kernel forgets everything.
  • Notebook file: a JSON file that stores your code, your text and the outputs. It does not store the variables, only the pictures and text printed last time.
flowchart LR
    B["Browser<br/>(cells you edit)"] -->|"run cell"| K["Kernel<br/>(Python process, holds variables)"]
    K -->|"output, tables, plots"| B
    B -->|"save"| F[("analysis.ipynb")]

The browser sends code to the kernel and shows what comes back; the variables live in the kernel, not in the file.

The notebook trap: hidden state

Because cells can run in any order, a notebook can reach a state that you cannot reproduce. Imagine you delete a cell that created a column, but the kernel still remembers the column. Everything seems to work until a colleague opens the file and gets an error. The fix is a habit: from time to time choose Kernel, Restart Kernel and Run All Cells. If the notebook still works from top to bottom, it is reproducible.

Other useful basics:

  • Put all your import statements in the first cell.
  • Use Markdown cells to explain what you did and why.
  • Use df.head() as the last line of a cell to inspect data. Avoid printing huge tables.
  • Shortcuts: Esc then A inserts a cell above, B below, D D deletes a cell, M turns a cell into Markdown.

Installing with Anaconda or Miniconda

Anaconda is a distribution that installs Python, a package manager called conda and hundreds of data-science packages (pandas, NumPy, Matplotlib, Jupyter) in one download. Miniconda is the same tool without the bundled packages: smaller, and you add only what you need. Both give you an Anaconda Prompt (on Windows) or work from any terminal. Conda environments play the role of virtual environments:

Terminal
conda create --name sales-analysis python=3.12 pandas jupyterlab
conda activate sales-analysis
python -c "import pandas; print(pandas.__version__)"

conda create makes the environment and installs pandas and JupyterLab into it in one step; conda activate switches to it; conda deactivate leaves it; conda env list shows all environments. Add more packages later with conda install matplotlib (or pip install inside the activated environment when a package is not on conda). The Anaconda Navigator app offers the same actions with buttons, including a "Launch JupyterLab" tile. Use conda when your team already does, or when you need non-Python libraries that pip cannot install; otherwise the pip route above is lighter.

Working in a notebook: cell types, Markdown, LaTeX and magics

A notebook has two main cell types. A code cell runs Python in the kernel; a Markdown cell holds formatted text: # Heading, **bold**, lists, links, tables and images. Switch a cell's type from the toolbar or with M (Markdown) and Y (code) in command mode. Press Shift+Enter to run a cell and render a Markdown cell. A third type, raw, is left untouched; it is only used when a notebook is converted to another format.

Markdown cells also render LaTeX between dollar signs, which is how analysts write formulas next to code: $\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i$ for inline math and $$ s^2 = \frac{\sum (x_i - \bar{x})^2}{n-1} $$ for a centered display.

Lines that start with % are magic commands, special to IPython and not part of Python:

Python
%timeit df["price"].sum()      # time one statement, many runs
# %%time as the first line of a cell times the whole cell
%matplotlib inline             # show plots inside the notebook (the default in recent versions)
%who                           # list the variables the kernel holds
!pip list                      # a leading ! runs a shell command

Stopping, restarting and exporting

  • Interrupt (the square Stop button, or I I) cancels a cell that is stuck or taking too long; the kernel and your variables survive.
  • Restart kernel wipes all variables and starts clean; combine it with "Run All" to prove the notebook is reproducible.
  • To share results, use File, Save and Export Notebook As (HTML, PDF, Markdown, a Python script), or the command line: jupyter nbconvert --to html analysis.ipynb. nbconvert can also execute a notebook while converting (--execute), which is handy in scheduled jobs. A notebook can be saved as a plain .py script with --to script.
  • Notebooks hold outputs, so before committing one to version control, clear the outputs (Edit, Clear Outputs of All Cells) or use a tool such as nbstripout; otherwise every diff is full of data and images.

Other ways to run pandas

You do not have to use JupyterLab. Pick what suits you:

  • VS Code has built-in notebook support with the Python and Jupyter extensions. You select the .venv interpreter and work in .ipynb files inside your editor.
  • Google Colab and similar hosted notebooks need no installation; pandas is already there. Your files must be uploaded, and the session is temporary.
  • Plain scripts (python analysis.py) are best for jobs that run on a schedule or on a server. Many teams explore in a notebook and then move the final code into a script.
  • Conda and Miniconda manage Python and packages together. If your team uses them, conda install pandas jupyterlab replaces the pip commands.

Common installation problems

  • ModuleNotFoundError: No module named 'pandas'. You installed pandas into a different Python than the one running your code. Activate the environment, then run python -m pip install pandas so that pip and Python always match.
  • Jupyter cannot see your packages. The notebook kernel uses another interpreter. Install jupyterlab inside the same virtual environment, or register the environment with python -m ipykernel install --user --name sales-analysis.
  • pip is not found. Use python -m pip instead.
  • Permission errors. Never use sudo pip. A virtual environment avoids the problem completely.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why do you create a virtual environment for each project?

    A virtual environment isolates a project's packages. Two projects can use different pandas versions without conflict.
  2. 2. What does the Jupyter kernel do?

    The kernel is the Python process behind the notebook. It executes cells and holds all variables until you restart it.
  3. 3. Which package must you install to read .xlsx files with pandas?

    pandas uses openpyxl as its engine for .xlsx files. It is optional, so it is not installed with pandas itself.
  4. 4. How do you check that a notebook does not depend on hidden state?

    A fresh kernel has no leftover variables. If everything still runs in order, the notebook is reproducible.

Summary

  • Use Python 3.11 or newer and make one virtual environment per project (python -m venv .venv, then activate it).
  • Install with pip install pandas; add optional packages such as openpyxl, pyarrow and matplotlib when needed.
  • Check the setup with pd.__version__ or pd.show_versions().
  • JupyterLab runs code in cells on a kernel; variables live in the kernel, not in the .ipynb file.
  • Prefer python -m pip to avoid mismatched interpreters, and use Restart and Run All to keep notebooks reproducible.

Next: Reading CSV Data, your first real data file.