Bringing The Best Out of Jupyter Notebooks For Data Science - by Parul Pandey - Towards Data Science
Bringing The Best Out of Jupyter Notebooks For Data Science - by Parul Pandey - Towards Data Science
Follow 568K Followers · Editors' Picks Features Deep Dives Grow Contribute About
This is your last free member-only story this month. Sign up for Medium and get an extra one
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 1/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 2/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
Table of Contents
1. Executing Shell Commands
2. Jupyter Themes
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 3/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
3. Notebook Extensions
4. Jupyter Widgets
5. Qgrid
6. Slideshow
The shell is a way to interact textually with the computer. The most popular
Unix shell is Bash(Bourne Again SHell ). Bash is the default shell on most
modern implementations of Unix and in most packages that provide Unix-
like tools for Windows.
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 4/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
In [1]: !ls
In [2]: !pwd
Hello World
In [5]: print(files)
In [7]: print(directory)
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 5/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
In [8]: type(directory)
IPython.utils.text.SList
2. Jupyter Themes
Theme-ify your Jupyter Notebooks!
If you are a person who gets bored while staring at the white background of
the Jupyter notebook, themes are just for you. The themes also enhance the
presentation of the code. You can find more about Jupyter themes here.
Let’s get to the working part.
Installation
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 6/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
jt -l
jt -r
You will have to reload the jupyter notebook everytime you change the
theme, to see the effect take place.
The same commands can also be run from within the Jupyter Notebook by
placing ‘ ! ’ before the command.
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 7/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 8/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 9/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
3. Notebook Extensions
Extend the possibilities
Notebook extensions let you move beyond the general vanilla way of using
the Jupyter Notebooks. Notebook extensions (or nbextensions) are
JavaScript modules that you can load on most of the views in your
Notebook’s frontend. These extensions modify the user experience and
interface.
Installation
Installation with conda:
Or with pip:
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 10/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
pip install jupyter_contrib_nbextensions && jupyter contrib
nbextension install --user
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 11/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
In case you couldn’t find the tab, a second small nbextension, can be
located under the menu Edit .
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 12/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
1. Hinterland
Hinterland enables code autocompletion menu for every keypress in a code
cell, instead of only calling it with the tab. This makes Jupyter notebook’s
autocompletion behave like other popular IDEs such as PyCharm.
2. Snippets
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 13/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
This extension adds a drop-down menu to the Notebook toolbar that allows
easy insertion of code snippet cells into the current notebook.
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 14/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
4. Table of Contents
This extension enables to collect all running headers and display them in a
floating window, as a sidebar or with a navigation menu. The extension is
also draggable, resizable, collapsible and dockable.
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 15/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
5. Collapsible Headings
Collapsible Headings allows the notebook to have collapsible sections,
separated by headings. So in case you have a lot of dirty code in your
notebook, you can simply collapse it to avoid scrolling it again and again.
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 16/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
6. Autopep8
Autopep8 helps to reformat/prettify the contents of code cells with just a
click. If you are tired of hitting the spacebar again and again to format the
code, autopep8 is your savior.
4. Jupyter Widgets
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 17/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
Installation
# pip
# Conda
Let us have a look at some of the widgets. For complete details, you can visit
their Github repository.
Interact
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 18/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
1. Basic Widgets
def f(x):
return x
# Generate a slider
interact(f, x=10,);
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 19/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
interact(f, x=True);
2. Advanced Widgets
Here is a list of some of the useful advanced widgets.
Play Widget
The Play widget is useful to perform animations by iterating on a sequence
of integers at a certain speed. The value of the slider below is linked to the
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 20/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
player.
play = widgets.Play(
# interval=10,
value=50,
min=0,
max=100,
step=1,
description="Press play",
disabled=False
slider = widgets.IntSlider()
widgets.HBox([play, slider])
Date picker
The date picker widget works in Chrome and IE Edge but does not currently
work in Firefox or Safari because they do not support the HTML date input
field.
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 21/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
widgets.DatePicker(
description='Pick a Date',
disabled=False
Color picker
widgets.ColorPicker(
concise=False,
description='Pick a color',
value='blue',
disabled=False
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 22/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
Tabs
tab = widgets.Tab()
tab.children = children
for i in range(len(children)):
tab.set_title(i, str(i))
tab
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 23/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
5. Qgrid
Make Data frames intuitive
Installation
Installing with pip:
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 24/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 25/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
6. Slideshow
Code is great when communicated.
Notebooks are an effective tool for teaching and writing explainable codes.
However, when we want to present our work either we display our entire
notebook(with all the codes) or we take the help of powerpoint. Not any
more. Jupyter Notebooks can be easily converted to slides and we can easily
choose what to show and what to hide from the notebooks.
Now go to the directory where the notebook is present and enter the
following code:
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 27/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
The slides get displayed at port 8000. Also, a .html file will be generated in
the directory, and you can also access the slides from there.
This would look even more classy with a themed background. Let us apply
the theme ’onedork’ to the notebook and then convert it into a slideshow.
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 28/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
These slides have a drawback i.e. you can see the code but cannot edit it.
RISE plugin offers a solution.
Installation
and then two more steps to install the JS and CSS in the proper places:
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 30/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
Let us now use RISE for the interactive slideshow. We shall re-open the
Jupyter Notebook we created earlier. Now we notice a new extension that
says “Enter/Exit RISE Slideshow.”
Click on it, and you are good to go. Welcome to the world of interactive
slides.
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 31/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
Why go with mere links when you can easily embed an URL, pdf, and videos
into your Jupyter Notebooks using IPython’s display module.
URLs
#Note that http urls will not be displayed. Only https are allowed
inside the Iframe
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 32/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
from IPython.display import IFrame
PDFs
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 33/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
Youtube Videos
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 34/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
Conclusion
These were some of the features of the Jupyter Notebooks that I found
useful and worth sharing. Some of them would be obvious to you while
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 35/36
13/08/2021 Bringing the best out of Jupyter Notebooks for Data Science | by Parul Pandey | Towards Data Science
some may be new. So, go ahead and experiment with them. Hopefully, they
will be able to save you some time and give you a better UI experience. Also
feel free to suggest other useful features in the comments.
Every Thursday, the Variable delivers the very best of Towards Data Science: from
hands-on tutorials and cutting-edge research to original features you don't want to
miss. Take a look.
https://towardsdatascience.com/bringing-the-best-out-of-jupyter-notebooks-for-data-science-f0871519ca29 36/36