Data Science and Data Proicessing

Bringing the best out of Jupyter Notebooks for Data Science

Enhance Jupyter Notebook’s productivity with these Tips & Tricks.

Reimagining what a Jupyter notebook can be and what can be done with it.


Table of Contents


1. Executing Shell Commands

In [1]: !ls
example.jpeg list tmp
In [2]: !pwd
/home/Parul/Desktop/Hello World Folder'
In [3]: !echo "Hello World"
Hello World
In [4]: files= !lsIn [5]: print(files)
['example.jpeg', 'list', 'tmp']
In [6]: directory = !pwdIn [7]: print(directory)
['/Users/Parul/Desktop/Hello World Folder']
In [8]: type(directory)
IPython.utils.text.SList

2. Jupyter Themes

pip install jupyterthemes
jt -l
# selecting a particular themejt -t <name of the theme># reverting to original Themejt -r
Left: original | Middle: Chesterish Theme | Right: solarizedl theme
Image for post

3. Notebook Extensions

Installation

conda install -c conda-forge jupyter_nbextensions_configurator
pip install jupyter_contrib_nbextensions && jupyter contrib nbextension install#incase you get permission errors on MacOS,pip install jupyter_contrib_nbextensions && jupyter contrib nbextension install --user
Image for post

1. Hinterland

Image for post

2. Snippets

Image for post

3. Split Cells Notebook

Image for post

4. Table of Contents

Image for post

5. Collapsible Headings

Image for post

6. Autopep8

Image for post

4. Jupyter Widgets

Installation

# pip
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension
# Conda
conda install -c conda-forge ipywidgets
#Installing ipywidgets with conda automatically enables the extension
# Start with some imports!from ipywidgets import interact
import ipywidgets as widgets

1. Basic Widgets

def f(x):
return x
# Generate a slider
interact(f, x=10,);
Image for post
# Booleans generate check-boxes
interact(f, x=True);
Image for post
# Strings generate text areas
interact(f, x='Hi there!');
Image for post

2. Advanced Widgets

Play Widget

play = widgets.Play(
# interval=10,
value=50,
min=0,
max=100,
step=1,
description="Press play",
disabled=False
)
slider = widgets.IntSlider()
widgets.jslink((play, 'value'), (slider, 'value'))
widgets.HBox([play, slider])
Image for post

Date picker

widgets.DatePicker(
description='Pick a Date',
disabled=False
)
Image for post

Color picker

widgets.ColorPicker(
concise=False,
description='Pick a color',
value='blue',
disabled=False
)
Image for post

Tabs

tab_contents = ['P0', 'P1', 'P2', 'P3', 'P4']
children = [widgets.Text(description=name) for name in tab_contents]
tab = widgets.Tab()
tab.children = children
for i in range(len(children)):
tab.set_title(i, str(i))
tab
Image for post

5. Qgrid

Installation

pip install qgrid
jupyter nbextension enable --py --sys-prefix qgrid
# only required if you have not enabled the ipywidgets nbextension yet
jupyter nbextension enable --py --sys-prefix widgetsnbextension
# only required if you have not added conda-forge to your channels yet
conda config --add channels conda-forge
conda install qgrid
Image for post

6. Slideshow

1. Jupyter Notebook’s built-in Slide option

Image for post
jupyter nbconvert *.ipynb --to slides --post serve
# insert your notebook name instead of *.ipynb
Image for post
Image for post

2. Using the RISE plugin

conda install -c damianavila82 rise
pip install RISE
jupyter-nbextension install rise --py --sys-prefix#enable the nbextension:
jupyter-nbextension enable rise --py --sys-prefix
Image for post
Image for post

6. Embedding URLs, PDFs, and Youtube Videos

URLs

#Note that http urls will not be displayed. Only https are allowed inside the Iframefrom IPython.display import IFrame
IFrame('https://en.wikipedia.org/wiki/HTTPS', width=800, height=450)
Image for post

PDFs

from IPython.display import IFrame
IFrame('https://arxiv.org/pdf/1406.2661.pdf', width=800, height=450)
Image for post

Youtube Videos

from IPython.display import YouTubeVideoYouTubeVideo('mJeNghZXtMo', width=800, height=300)
Image for post

Conclusion

+ Recent posts