Jupyter cheatsheet

Jupyter: IPython magics and tips

8 common Jupyter tasks.

Time a statement

Run a statement many times and report the average. %%timeit does the same for a whole cell.

%timeit sum(range(1000))

Time a cell

Report how long the whole cell took to run once.

%%time
result = sum(range(10_000_000))

Show plots inline

Display Matplotlib charts below the cell.

%matplotlib inline

Reload edited modules automatically

Pick up changes to imported .py files without restarting the kernel.

%load_ext autoreload
%autoreload 2

Run a shell command

Prefix a command with ! to run it in the shell.

!ls -lh data/

Show help for an object

Append ? to see documentation, or ?? to see the source.

pd.DataFrame.merge?

Display rich output

Show several values in one cell, such as DataFrames and images.

from IPython.display import display

display(df.head(), df.describe())

List variables in memory

Show the variables defined in the notebook.

%whos

Was this page helpful?