Jupyter cheatsheet
Jupyter: Convert and automate
6 common Jupyter tasks.
Convert to HTML
Export a notebook as a standalone HTML page.
jupyter nbconvert --to html notebook.ipynb
Convert to a Python script
Export the code cells as a .py file.
jupyter nbconvert --to script notebook.ipynb
Run a notebook from the command line
Execute every cell and save the results in a new notebook.
jupyter nbconvert --to notebook --execute notebook.ipynb --output executed.ipynb
Run a notebook with parameters
Run a notebook with different parameters. Tag one cell "parameters" to define the defaults. Needs papermill installed.
papermill input.ipynb output.ipynb -p alpha 0.5 -p dataset sales
Keep outputs out of Git
Remove outputs and metadata before committing, so diffs stay small. Needs nbstripout.
nbstripout --install
Learn the key shortcuts
Shift+Enter runs a cell and moves on. Esc enters command mode, where A and B insert cells above or below, DD deletes a cell, M makes markdown and Y makes code.
Shift+Enter run cell
Esc A / B insert cell above / below
Esc D D delete cell
Esc M / Y markdown / code