Jupyter Notebooks (.ipynb)
Table of contents
- What is a Jupyter Notebook?
- Key Features
- File Structure
- How Jupyter Notebooks Work
- Using Jupyter Notebooks in Google Colab
- Common Use Cases
- Troubleshooting
- Additional Resources
What is a Jupyter Notebook?
A Jupyter Notebook (.ipynb file) is an interactive document that combines live code, visualizations, and narrative text in a single file. The .ipynb extension stands for “IPython Notebook,” reflecting its origins in the IPython project. These notebooks are widely used in data science, machine learning, scientific computing, and education because they allow you to write and execute code in small chunks (called “cells”) and see results immediately.
Key Features
- Interactive Execution: Run code cell by cell and see output instantly
- Multiple Languages: While commonly used with Python, Jupyter supports many programming languages (Julia, R, and more)
- Rich Output: Display text, images, plots, tables, LaTeX equations, HTML, and interactive widgets
- Markdown Support: Mix code with formatted text, headings, lists, and documentation
- Portable: Share notebooks as
.ipynbfiles that others can run and modify
File Structure
An .ipynb file is actually a JSON document that contains:
- Cells: Code cells (executable) and Markdown cells (documentation)
- Outputs: Results from executed code cells (text, images, data)
- Metadata: Information about the kernel, language version, and cell execution order
Example structure:
{
"cells": [
{
"cell_type": "markdown",
"source": ["# My First Notebook"]
},
{
"cell_type": "code",
"source": ["print('Hello, World!')"],
"outputs": [...]
}
],
"metadata": {...}
}
How Jupyter Notebooks Work
Local Jupyter Environment
- Install Jupyter:
pip install jupyter - Launch Jupyter:
jupyter notebookorjupyter lab - Browser Interface: Opens in your web browser, running on a local server
- Kernel: A computational engine (e.g., Python interpreter) runs in the background
- Execution: You edit cells in the browser; the kernel executes code and returns results
VS Code Integration
VS Code has built-in support for Jupyter notebooks:
- Open
.ipynbfiles directly in VS Code - Run cells inline without launching a separate Jupyter server
- Use the same Python environment configured for your workspace
- Debug notebook code with breakpoints
Using Jupyter Notebooks in Google Colab
Google Colab (Colaboratory) is a free, cloud-based Jupyter notebook environment provided by Google. It requires no local setup and provides free access to GPUs and TPUs for machine learning tasks.
Key Benefits of Colab
- Zero Installation: Runs entirely in your browser—no local setup required
- Free GPU/TPU Access: Accelerate machine learning and deep learning workloads
- Google Drive Integration: Save notebooks directly to Google Drive
- Collaboration: Share notebooks like Google Docs; multiple users can edit simultaneously
- Pre-installed Libraries: Common data science packages (NumPy, Pandas, TensorFlow, PyTorch) are already installed
How to Use Colab
1. Access Google Colab
Visit https://colab.research.google.com and sign in with your Google account.
2. Create a New Notebook
- Click File → New Notebook
- Or upload an existing
.ipynbfile: File → Upload Notebook
3. Open from Google Drive
- Click File → Open Notebook
- Choose from Recent, Google Drive, GitHub, or upload a file
4. Work with Cells
Code Cell:
# Click in a cell and type code
import numpy as np
print(np.array([1, 2, 3]))
- Press
Shift + Enterto run the cell - Press
Ctrl/Cmd + Enterto run without moving to the next cell
Text Cell:
- Click + Text to add a Markdown cell
- Format using Markdown syntax
5. Enable GPU/TPU
For machine learning tasks:
- Click Runtime → Change runtime type
- Select GPU or TPU from the Hardware accelerator dropdown
- Click Save
6. Install Additional Packages
Colab comes with many libraries pre-installed, but you can add more:
!pip install package-name
7. Mount Google Drive
Access files from your Google Drive:
from google.colab import drive
drive.mount('/content/drive')
8. Save Your Work
- Auto-save: Colab automatically saves to Google Drive (if opened from Drive)
- Manual save: File → Save or
Ctrl/Cmd + S - Download: File → Download → Download .ipynb
Colab vs. Local Jupyter
| Feature | Google Colab | Local Jupyter |
|---|---|---|
| Setup | No installation needed | Requires Python & Jupyter installation |
| Cost | Free (with usage limits) | Free, but requires your hardware |
| GPU/TPU | Free access with limits | Requires compatible hardware |
| Storage | Google Drive | Local disk |
| Internet | Required | Optional (for local work) |
| Collaboration | Real-time sharing | Requires file sharing |
| Environment | Managed by Google | Full control over dependencies |
| Session Time | Limited (disconnects after ~12 hours idle) | No time limits |
Common Colab Tips
Upload Files:
from google.colab import files
uploaded = files.upload()
Download Files:
from google.colab import files
files.download('result.csv')
Check GPU Availability:
import tensorflow as tf
print("GPU Available:", tf.config.list_physical_devices('GPU'))
Clear Output:
- Click the X icon next to a cell’s output
- Or: Runtime → Restart runtime to clear all outputs
Common Use Cases
- Data Analysis: Explore datasets interactively with Pandas and visualization libraries
- Machine Learning: Train models with TensorFlow, PyTorch, scikit-learn
- Scientific Computing: Numerical simulations, statistical analysis
- Teaching & Learning: Interactive tutorials and coding exercises
- Documentation: Create reports that combine code, results, and explanations
Troubleshooting
Notebook won’t run locally:
- Ensure Jupyter is installed:
pip install jupyter - Check that the correct kernel is selected
- Verify your Python environment has required packages
Colab session disconnected:
- Colab disconnects after ~90 minutes of inactivity or ~12 hours of continuous use
- Save your work regularly to Google Drive
- Re-run cells after reconnecting
Module not found in Colab:
- Install the package:
!pip install package-name - Restart runtime if needed: Runtime → Restart runtime
Out of memory:
- Use smaller datasets or batch sizes
- Enable GPU/TPU for better performance
- In Colab, restart runtime to clear memory
Additional Resources
Last updated: January 2026