Photo by Lorenzo Herrera on Unsplash

Getting More Out of Your Jupyter Notebooks

iPython flavoured

Shortcuts

Switches

!pip show ipythonName: ipython
Version: 7.19.0
Summary: IPython: Productive Interactive Computing
Home-page: https://ipython.org
Author: The IPython Development Team
Author-email: ipython-dev@python.org
License: BSD
Location: /usr/lib/python3.8/site-packages
Requires:
Required-by: jupyter-console, ipykernel
?list
Docstring
  • %lsmagic, which lists all the magic commands available.
  • %time, which times the execution of a cell.
  • %timeit, which times the execution per iteration, after running the code for 100,000 times (by default).
  • %matplotlib inline, which displays plots at the end of the cell execution (even if there is no .show() method called).
  • %matplotlib notebook, which displays matplotlib in an interactive way. You can now zoom, or get point coordinates on the fly!
  • %who_ls, which will list the variables allocated in the current environment. You can add a data type as an argument to filter the output.
  • %config InlineBackend.figure_format =’retina’, which renders plots at “retina” resolution, for a smoother experience on retina display.
%system pip show ipython['Name: ipython',
'Version: 7.19.0',
'Summary: IPython: Productive Interactive Computing',
'Home-page: https://ipython.org',
'Author: The IPython Development Team',
'Author-email: ipython-dev@python.org',
'License: BSD',
'Location: /usr/lib/python3.8/site-packages',
'Requires: ',
'Required-by: jupyter-console, ipykernel']
%timeit [i*i for i in range(50)]2.61 µs ± 228 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)string_s, integer_i, tuple_t = 'wololo', 4, (35, 42)
%who_ls tuple
['tuple_t']

Kernels

# Create a folder to host the virtual environment
!mkdir virtual_environments
# Move to the folder and create the virtual environment
!cd virtual_environments
!virtualenv my_env
# Activate the virtual environment
!source my_env/bin/activate
# Install ipykernel in the virtual environment
!pip install ipykernel
# Let Jupyter know there is a new kid on the block
!python -m ipykernel install --user --name=my_env
# List kernels installed
!jupyter kernelspec list
# Uninstall kernel
!jupyter kernelspec uninstall [kernelName]

Extensions

!pip install jupyter_contrib_nbextensions
!jupyter contrib nbextension install --user
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

Final Thoughts

Photo by Greg Rakozy on Unsplash

--

--

Data Scientist

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store