Here are some extensions and tips that help we get nice notebooks and easily presenting to others.
Collapse heading extension / code folding extension
The jupyter contrib nbextensions Python package contains a code-folding extension that can be enabled within the notebook.
Installation
To install using command line:
1 | pip install jupyter_contrib_nbextensions |
To make life easier in managing them, I’d also recommend the jupyter nbextensions configurator package. This provides an extra tab in your Notebook interface from where you can easily (de)activate all installed extensions.
1 | pip install jupyter_nbextensions_configurator |
Then the package will provide a UI that you can open in your browser.
If your dashboard is at
1 | http://localhost:8888/custom/base/url/tree |
then you’ll find the configurator UI page at
1 | http://localhost:8888/custom/base/url/nbextensions |
It will also be opened from the tab on your dashboard
Enable “Collapsible Headings”
Now, go to “Nbextensions” tab, and enable the functions you need:
Extensions that I usually enable
Collapsible Headings
Limit Output: 1000
Snippets
Table of Contents
Codefolding
Hinterland
Split Cells Notebook
Some extra sweet?
It’s nice to have all those foldings inside our notebooks when we are doing DS work and presenting this to others. However, when we share the notebooks to others, especially those who don’t have the same jupyter environment setup like us, how can we make sure they can see the same nice formatted report?
Well, run the following magic command and you will see an html exported with the same “collapsible heading” format!1
jupyter nbconvert --to html_ch some_notebook.ipynb
jupyter nbconvert supports many other formats e.g slides, latex, pandoc, please refer to their documentation
Use Jupyter Themes
Got tired with the default notebook style? You can change to other themes and different plotting styles!1
2
3
4
5
6pip install jupyterthemes
jt -l
# selecting a particular theme
jt -t <name of the theme>
# reverting to original Theme
jt -r
You can have a look of how each of the theme look like here
Other interesting tools
Interactive dataframe output
1 | # only required if you have not added conda-forge to your channels yet |
1 | import qgrid |
Embed URL, PDF, or Videos!
1 | #Note that http urls will not be displayed. Only https are allowed inside the Iframe |
Other tips
Run jupyter without token
1 | jupyter notebook --ip='*' --NotebookApp.token='' --NotebookApp.password='' --port=51111 --no-browser |
Replace tab with space
Edit -> Replace -> Use regex -> \t -> replace with 4 spaces