AI & Machine Learning
Jupyter Notebook Complete Guide
Master Jupyter Notebook for data science and machine learning development with Python 3.12, JupyterLab, extensions, kernels, and production deployment on Ubuntu 24.04 LTS.
What you'll learn
- Install JupyterLab and configure for data science work
- Work with Jupyter cells, kernels, and magic commands
- Analyse data with Pandas and NumPy
- Create visualisations with Matplotlib and Seaborn
- Use JupyterLab extensions for productivity
- Deploy JupyterHub for team collaboration
- Export notebooks to PDF, HTML, and Python scripts
Installation
Bash
1python3.12 -m venv .venv && source .venv/bin/activate
2
3pip install jupyterlab pandas numpy matplotlib seaborn scikit-learn
4pip install jupyterlab-git jupyterlab-lsp python-lsp-server
5
6# Launch JupyterLab
7jupyter lab --port 8888 --no-browser
8
9# Access at http://localhost:8888/?token=...Interface & Cells
Python
1# Magic commands
2%timeit sum(range(1000)) # time a single expression
3%%timeit # time entire cell
4import numpy as np
5np.random.randn(1000).mean()
6
7%matplotlib inline # render plots inline
8%load_ext autoreload # auto-reload modules
9%autoreload 2
10
11# Shell commands
12!pip install plotly
13!ls -la data/
14
15# Keyboard shortcuts (command mode)
16# A — insert cell above | B — insert cell below
17# DD — delete cell | Z — undo | Shift+Enter — run cellData Analysis with Pandas
Python
1import pandas as pd
2import numpy as np
3
4# Load data
5df = pd.read_csv('data/sales.csv', parse_dates=['date'])
6
7# Explore
8print(df.shape, df.dtypes)
9df.describe()
10df.isnull().sum()
11
12# Clean
13df = df.dropna(subset=['revenue'])
14df['revenue'] = df['revenue'].clip(lower=0)
15
16# Aggregate
17monthly = (
18 df.groupby(df['date'].dt.to_period('M'))
19 .agg(total_revenue=('revenue', 'sum'), orders=('id', 'count'))
20 .reset_index()
21)
22
23# Merge
24products = pd.read_csv('data/products.csv')
25df = df.merge(products, on='product_id', how='left')Visualisation
Python
1import matplotlib.pyplot as plt
2import seaborn as sns
3
4# Style
5plt.style.use('seaborn-v0_8-whitegrid')
6sns.set_palette('husl')
7
8fig, axes = plt.subplots(1, 2, figsize=(14, 5))
9
10# Line chart
11axes[0].plot(monthly['date'].astype(str), monthly['total_revenue'])
12axes[0].set_title('Monthly Revenue')
13axes[0].tick_params(axis='x', rotation=45)
14
15# Distribution
16sns.histplot(df['revenue'], bins=50, kde=True, ax=axes[1])
17axes[1].set_title('Revenue Distribution')
18
19plt.tight_layout()
20plt.savefig('charts/revenue_analysis.png', dpi=150)
21plt.show()Extensions & Productivity
Bash
1# Useful extensions
2pip install jupyterlab-git # Git integration
3pip install aquirdturtle_collapsible_headings # collapsible sections
4pip install jupyterlab_execute_time # cell execution time
5pip install nbformat black # auto-format with Black
6
7# nbconvert — export notebooks
8jupyter nbconvert --to html analysis.ipynb
9jupyter nbconvert --to pdf analysis.ipynb
10jupyter nbconvert --to script analysis.ipynb # → analysis.pyDeployment
Bash
1# JupyterHub — multi-user team server
2pip install jupyterhub
3jupyterhub --generate-config
4# Edit jupyterhub_config.py for authentication (PAM, OAuth, LDAP)
5jupyterhub -f jupyterhub_config.py
6
7# Docker deployment
8docker run -p 8888:8888 -v $(pwd)/notebooks:/home/jovyan/work jupyter/datascience-notebook
9
10# Scheduled notebook execution with papermill
11pip install papermill
12papermill analysis.ipynb output.ipynb -p date "2025-09-18" -p threshold 0.8