Stop 06 · Python for Data AnalysisTopics · 2/12

Jupyter Notebooks

Part of the Data Analyst Roadmap

In short

Writing a whole script and running it blind is painful when you're exploring data. Notebooks let you run one small piece, look at the result, and decide the next step.

An interactive coding environment mixing code, output and notes in one document — the standard way analysts explore data, since you can run one cell at a time and see results immediately.

The jaadu writes in a lab notebook beside a bubbling test tube.

Think of it like this

Your practical lab record

In college practicals you write the aim, do one experiment, note the observation right beside it, then move on. A notebook works the same: a cell of code, its output just below, and your notes in between. Anyone can read it later and follow along.

Watch it happen

What happens when you press Shift+Enter

You
Notebook
Kernel

Shift+Enter on cell 1

1/5You run the first cell, which loads a CSV into a variable called df.

The big ideas

What you need to know

Code cells and text cells

Code cells run Python. Markdown cells hold headings and notes explaining why you did something.

The kernel keeps state

Variables live in the kernel's memory. Run cells out of order and you can get confusing results.

Shift+Enter is your friend

Runs the cell and moves to the next one. Learn a few shortcuts and you'll fly.

Free hosted options

Google Colab and Kaggle Notebooks run in the browser, so you can start without installing anything.

See it in code

Walk through the code

python
1# Cell 1: load once2import pandas as pd3df = pd.read_csv("orders.csv")4 5# Cell 2: look6df.head()7 8# Cell 3: explore one question at a time9df["city"].value_counts()

1/3Slow work like loading a file goes in its own cell, so you run it only once.

Three small cells instead of one long script. The last line of a cell is shown automatically, so no print needed.

Save yourself the pain

Common mistakes

Oops

Running cells in random order, then sharing a notebook that breaks for others.

Do this instead

Before sharing, use Restart and Run All. If it runs top to bottom cleanly, it's safe.

Oops

Pages of code with zero notes.

Do this instead

Add a short markdown cell above each section: what question you're answering and what you found.

Your mission

A notebook someone else can read

~20 min

Quick check

You ran cell 5 before cell 2 and now see strange values. What's the cleanest fix?

Go deeper

  1. 1Install Jupyter (or use a free hosted option) and run your first notebook.
  2. 2Practice mixing markdown notes with code cells to document your thinking.
  3. 3Learn keyboard shortcuts for running cells quickly (Shift+Enter, etc).

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge