Getting Started with Jupyter Notebooks
Learn to use Jupyter notebooks for interactive coding, data analysis, and sharing your work.
Getting Started with Jupyter Notebooks
Jupyter notebooks are the standard tool for interactive data science work. They let you write code, see results immediately, add explanations, and share your analysis - all in one document. If you're learning Python or R for data work, you'll spend a lot of time in Jupyter.
What is a Jupyter Notebook?
A Jupyter notebook is an interactive document that combines:
- Code cells - Write and run Python or R code
- Output - See results, charts, and tables inline
- Markdown cells - Add formatted text, explanations, and documentation
- Rich media - Display images, HTML, and interactive widgets
The name "Jupyter" comes from Julia, Python, and R - the three languages it originally supported. Today it works with dozens of languages, but Python is most common.
Why Use Notebooks?
Exploratory analysis. When you're investigating data, you want to try things quickly and see results. Notebooks let you run code in chunks, inspect outputs, and iterate fast.
Documentation built-in. You can explain your thinking alongside your code. This makes notebooks great for sharing analysis with colleagues who want to understand your approach.
Visualization inline. Charts and plots appear right below the code that generated them. No switching between windows.
Reproducibility. A notebook captures your entire analysis workflow. Others can run it and get the same results.
Installing Jupyter
Option 1: With Anaconda (Recommended for beginners)
Anaconda includes Jupyter, Python, and common data science packages:
- Download Anaconda from anaconda.com
- Run the installer
- Open Anaconda Navigator and launch Jupyter Notebook
Option 2: With pip
If you already have Python installed:
pip install jupyter
Then run:
jupyter notebook
Option 3: JupyterLab
JupyterLab is the newer interface with more features:
1pip install jupyterlab
2jupyter lab
3The Interface
When you launch Jupyter, it opens in your web browser. You'll see:
File browser - Navigate your folders and open notebooks (.ipynb files)
Notebook view - The main editing area with cells
Toolbar - Buttons for common actions (run, stop, save)
Kernel indicator - Shows whether code is running
Working with Cells
Notebooks are made of cells. Each cell is either:
Code Cells
Type Python code and press Shift+Enter to run:
1import pandas as pd
2df = pd.read_csv('data.csv')
3df.head()
4The output appears directly below the cell.
Markdown Cells
Write formatted text using Markdown syntax:
1## Analysis Summary
2
3This section explores the **key findings** from our data:
4
5- Finding 1
6- Finding 2
7- Finding 3
8Press Shift+Enter to render the formatted text.
Essential Keyboard Shortcuts
These will speed up your work significantly:
| Action | Shortcut |
|---|---|
| Run cell | Shift + Enter |
| Run cell, stay in place | Ctrl + Enter |
| Insert cell below | B (in command mode) |
| Insert cell above | A (in command mode) |
| Delete cell | DD (in command mode) |
| Switch to Markdown | M (in command mode) |
| Switch to Code | Y (in command mode) |
| Enter command mode | Esc |
| Enter edit mode | Enter |
Command mode (blue cell border): Navigate and manipulate cells Edit mode (green cell border): Type in a cell
Best Practices
Keep cells focused
Each cell should do one thing. This makes debugging easier and helps readers follow your logic.
1# Good: One operation per cell
2df = pd.read_csv('sales.csv')
3df['total'] = df['quantity'] * df['price']
df.groupby('region')['total'].sum()
Add Markdown explanations
Don't just show code - explain what you're doing and why:
1## Data Cleaning
2
3The raw data has several issues we need to address:
4- Missing values in the 'region' column
5- Duplicate transaction IDs
6- Negative quantities (likely returns)
7Restart and run all
Before sharing, restart the kernel and run all cells from top to bottom. This catches issues where cells depend on deleted code or out-of-order execution.
Kernel > Restart & Run All
Use meaningful names
Name your notebooks descriptively:
- Good:
2024-01-sales-analysis.ipynb - Bad:
Untitled.ipynb
Common Patterns
Data exploration workflow
1# Load data
2import pandas as pd
3df = pd.read_csv('data.csv')
4
5# Quick look
6df.head()
71# Shape and types
2print(f"Rows: {len(df)}, Columns: {len(df.columns)}")
3df.dtypes
41# Summary statistics
2df.describe()
31# Check for missing values
2df.isnull().sum()
3Visualization
1import matplotlib.pyplot as plt
2
3# Enable inline plots
4%matplotlib inline
5
6# Create a chart
7df['category'].value_counts().plot(kind='bar')
8plt.title('Sales by Category')
9plt.show()
10Suppress output
Add a semicolon to prevent output:
1fig, ax = plt.subplots(figsize=(10, 6)); # No extra output
2Notebooks vs Scripts
Use notebooks for:
- Exploratory analysis
- Learning and experimentation
- Sharing analysis with explanations
- Quick prototyping
Use scripts (.py files) for:
- Production code
- Reusable functions and modules
- Automation
- Version control (notebooks don't diff well)
Many data scientists prototype in notebooks, then move finalized code to scripts.
JupyterLab vs Classic Notebook
Classic Notebook - Simpler, one notebook at a time, lighter weight
JupyterLab - Multiple tabs, file browser, terminal, more IDE-like
Both work with the same .ipynb files. JupyterLab is the direction Jupyter is heading, but classic notebooks are still widely used.
Next Steps
- Install Jupyter using one of the methods above
- Create a new notebook and run some basic Python
- Load a dataset with pandas and explore it
- Add Markdown to document your analysis
- Practice shortcuts until they're automatic
Notebooks are a tool - the more you use them, the more natural they become. Start simple, and you'll develop your own workflow over time.
