ENGIMY.IO - CHEATSHEET
JUPYTER NOTEBOOK × INTERACTIVE COMPUTING
REFERENCE vJupyter Notebook 7.x / JupyterLab 4.x

Jupyter Notebook Quick Reference

Interactive coding, data exploration, and visualisation – all in one place.

Installation & Setup

# Install via pip
pip install notebook
pip install jupyterlab

# Install via conda
conda install notebook
conda install jupyterlab

# Launch Jupyter Notebook
jupyter notebook
jupyter notebook --port 8888

# Launch JupyterLab
jupyter lab

# List running servers
jupyter notebook list

# Stop server
jupyter notebook stop 8888

# Configuration
jupyter notebook --generate-config

Notebook Interface – Key Areas

  • Kernel – the computation engine (Python, R, Julia, etc.)
  • Cell – individual unit of code, text, or markdown.
  • Toolbar – run, stop, save, insert cells, etc.
  • Command Palette – search and execute commands.
  • File Browser – manage notebooks, files, and directories.

Cell Types

Cell Type Purpose Shortcut
CodeExecutable code (Python, etc.)y
MarkdownFormatted text (headings, lists, LaTeX)m
RawText with no formattingr
HeadingLegacy; use Markdown # instead1-6 (deprecated)

Keyboard Shortcuts (Command Mode)

# Navigation
Up/Down      # move between cells
a            # insert cell above
b            # insert cell below
j/k          # move selection down/up
Shift+Up     # select multiple cells above
Shift+Down   # select multiple cells below

# Cell Operations
y            # change to Code cell
m            # change to Markdown cell
r            # change to Raw cell
d,d          # delete selected cell
z            # undo cell deletion
c            # copy cell
x            # cut cell
v            # paste cell below
Shift+v      # paste cell above
o            # toggle output scroll
Shift+o      # toggle output
l            # toggle line numbers
s            # save notebook
i            # interrupt kernel
0,0          # restart kernel (press twice)

# Run Cells
Enter        # enter edit mode
Ctrl+Enter   # run cell
Shift+Enter  # run cell and select below
Alt+Enter    # run cell and insert below

# Help
h            # show keyboard shortcuts
Shift+Tab    # show docstring (in edit mode)
?            # object help (in code cell)

Magic Commands (IPython)

Magics are special commands that control the behavior of the notebook.

Line Magics (prefixed with %)
# Run external files
%run script.py
%run script.py arg1 arg2

# Time execution
%time
%timeit -n 100 -r 5

# System commands
%ls
%pwd
%cd /path/to/dir

# Environment variables
%env
%env MY_VAR=value

# Debugging
%debug          # enter debugger after exception
%pdb            # auto-debug on error

# List / load extensions
%load_ext autoreload
%autoreload 2   # auto-reload modules before execution

# Display
%matplotlib inline  # show plots inline
%matplotlib notebook  # interactive plots
%config InlineBackend.figure_format = 'retina'
Cell Magics (prefixed with %%)
# Run different language
%%bash
echo "Hello from bash"
ls -la

%%html

HTML in notebook

%%javascript console.log('JS in notebook'); %%latex \int_0^\infty e^{-x} dx = 1 # Time entire cell %%time import time time.sleep(2) # Write to file %%writefile output.txt This is written to file # Capture output %%capture print('This is captured') # Interactive widgets %%widget # ...

Markdown in Notebooks

Basic Syntax
# Heading 1
## Heading 2
### Heading 3

**Bold text**
*Italic text*
`inline code`

- bullet list
- item 2

1. numbered list
2. item 2

[Link text](url)
![alt text](image.png)

> blockquote

---

Horizontal rule
LaTeX Math (inline)
$E = mc^2$
$\sum_{i=1}^n i = \frac{n(n+1)}{2}$

# Block equations
$$
\int_0^\infty e^{-x} dx = 1
$$

$$
\begin{bmatrix}
1 & 2 \\
3 & 4
\end{bmatrix}
$$
Tables
| Header 1 | Header 2 |
|----------|----------|
| cell 1   | cell 2   |
| cell 3   | cell 4   |

Kernels

Jupyter supports multiple language kernels.

# List available kernels
jupyter kernelspec list

# Install additional kernels
pip install ipykernel
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"

pip install r-irkernel
pip install bash_kernel
python -m bash_kernel.install

# Change kernel in notebook
Kernel → Change Kernel → select

# Remove kernel
jupyter kernelspec remove myenv

Widgets (ipywidgets)

Interactive UI components for data exploration.

# Install
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension

# Basic widgets
import ipywidgets as widgets
from IPython.display import display

# Slider
slider = widgets.IntSlider(
    value=5, min=0, max=10, step=1,
    description='Slider:'
)
display(slider)

# Text input
text = widgets.Text(description='Name:')
display(text)

# Dropdown
dropdown = widgets.Dropdown(
    options=['Option 1', 'Option 2', 'Option 3'],
    description='Select:'
)
display(dropdown)

# Interact decorator
from ipywidgets import interact

@interact(x=(0, 10))
def f(x):
    return x**2

# Layout
button = widgets.Button(description='Click me')
output = widgets.Output()

def on_button_click(b):
    with output:
        print('Button clicked!')

button.on_click(on_button_click)
display(button, output)

File Operations

# Read CSV
import pandas as pd
df = pd.read_csv('data.csv')

# Load image
from IPython.display import Image
Image('image.png')

# Display HTML
from IPython.display import HTML
HTML('

Hello

') # Display video from IPython.display import Video Video('video.mp4') # Display audio from IPython.display import Audio Audio('audio.wav')

Exporting Notebooks

# From UI
File → Download as → (.ipynb, .html, .pdf, .py, .md, .rst, etc.)

# Command line
jupyter nbconvert --to html notebook.ipynb
jupyter nbconvert --to pdf notebook.ipynb
jupyter nbconvert --to python notebook.ipynb
jupyter nbconvert --to markdown notebook.ipynb

# With execute
jupyter nbconvert --execute --to html notebook.ipynb

# With output
jupyter nbconvert --to notebook --execute --output output.ipynb notebook.ipynb

JupyterLab vs Notebook

Feature Jupyter Notebook JupyterLab
InterfaceSingle-documentMulti-tab, IDE-like
ExtensionsLimitedRich extension ecosystem
File browserYesYes, integrated
TerminalYesYes, integrated
DebuggerBasicAdvanced (with xeus-python)
Drag and dropNoYes
Command paletteLimitedFull (Ctrl+Shift+C)

Useful Extensions

For Jupyter Notebook
  • nbextensions – collection of notebook extensions.
  • jupyter_contrib_nbextensions – install with pip install jupyter_contrib_nbextensions.
For JupyterLab
jupyter labextension install @jupyterlab/toc  # Table of Contents
jupyter labextension install @jupyterlab/git
jupyter labextension install @jupyterlab/debugger
jupyter labextension install @jupyterlab/datagrid

Display and Visualisation

# Matplotlib (inline)
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.show()

# Plotly (interactive)
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x='sepal_width', y='sepal_length')
fig.show()

# Pandas table styling
df.style.background_gradient(cmap='coolwarm')

# Rich output
from IPython.display import display, HTML
display(HTML('

Styled output

')) # Progress bar from tqdm import tqdm for i in tqdm(range(100)): pass

Best Practices

  • Use Markdown cells – document your analysis with headings and explanations.
  • Split code into logical cells – each cell should do one thing.
  • Use magic commands for timing%timeit and %%time.
  • Keep notebook linear – avoid running cells out of order.
  • Restart kernel regularly – ensure reproducibility.
  • Use __name__ == "__main__" – when converting to Python scripts.
  • Version control notebooks – be careful with output cells; use nbstripout to strip outputs.
  • Use environment variables – for configuration paths.
  • Use logging – not print, for better debugging.
  • Export to scripts – for production-ready code.
  • Use %load_ext autoreload – auto-reload modules during development.

Common Troubleshooting

  • Kernel not starting? – check Python environment, install ipykernel.
  • Plots not showing? – use %matplotlib inline.
  • Widgets not working? – install ipywidgets and enable extensions.
  • Out of memory? – restart kernel, clear outputs, use gc.collect().
  • Slow execution? – use %timeit to profile, vectorise operations.
  • Can't save? – check file permissions; use Save and Checkpoint.
📌 Quick Reference
Launch: jupyter notebook / jupyter lab
Cell types: Code (y), Markdown (m), Raw (r)
Run: Ctrl+Enter (run), Shift+Enter (run + select below)
Key magics: %run, %time, %timeit, %matplotlib inline, %cd, %env
Cell magics: %%bash, %%html, %%javascript, %%latex, %%writefile
Widgets: ipywidgets with interact decorator
Export: nbconvert --to html / pdf / python / markdown
Best practice: document with Markdown, keep cells focused, restart kernel
← Back to All Cheatsheets