Supercharging Jupyter Notebooks

Supercharging Jupyter Notebooks

Supercharging Jupyter Notebooks - Jupyter Notebooks are currently the hottest programming environment for Pythonistas the world over, especially those who are into Machine Learning and Data Science.

Supercharging Jupyter Notebooks - Jupyter Notebooks are currently the hottest programming environment for Pythonistas the world over, especially those who are into Machine Learning and Data Science.

I discovered Jupyter Notebooks when I first started to get serious about Machine Learning a few months ago. Initially, I was simply amazed, loved how everything ran inside my browser. However, I soon got disillusioned and found the stock Jupyter Notebook interface to be very basic lacking a number of useful features. That’s when I decided to go hunting for some Jupyter Notebook hacks.

In this article, I present a number of Jupyter Notebook add-ons/extensions and a few jupyter commands that will enhance your Jupyter Notebooks and increase your productivity. In short, *Supercharge your *Jupyter Notebooks.

Once you follow the instructions below, your Jupyter Notebooks will have the following awesome features (and more, if you want):

  1. Ability to switch between multiple Conda environments on the fly without having to restart the Jupyter Notebook.
  2. 1-click clickable *Table of Contents *generation (you’re going to love this one!)
  3. A super useful pop-up Scratch Pad (my favorite feature!), where you can play around and test your code on the side without having to change anything in the primary notebook.
  4. Code Folding inside the code cells. I wonder why this feature was not part of the stock Jupyter Notebooks already.
  5. 1-click Code Cell hiding, an important feature when you are telling your data story through visualizations….people are usually interested in your graphs and charts, not the code!
  6. A super cool Variable Inspector!
  7. A Spellchecker for Markdown cells.
  8. ZenMode for those late-night coding sessions.
  9. A Code Snippets menu to add commonly used python constructs like List comprehensions on the fly.
  10. And finally, absolutely the best feature, a soothing beautiful midnight blue color scheme to save your eyes!

    Time to Supercharge!

First up, we will make sure our notebooks have a nice dark theme that is soothing to the eyes. The stock white background can make your eyes bleed if you are working long hours on a daily basis. Anyway, once you go dark, you’re never switching back 😉

Install the dark theme using the following commands,

# Kill and exit the Notebook server
# Make sure you are in the base conda environment
conda activate base

# install jupyterthemes
pip install jupyterthemes

# upgrade to latest version
pip install --upgrade jupyterthemes

Once the package is installed and upgraded, run the following command and turn your stock white themed Jupyter Notebooks into a lovely Deep Blue Midnight Theme. Your eyes will love you for this.

# Enable Dark Mode
jt -t onedork -fs 95 -altp -tfs 11 -nfs 115 -cellw 88% -T

Next, let’s see if we can add all of our custom environments created in Anaconda as kernels in the Jupyter Notebooks. This would ensure that we can switch environments by simply selecting them in the *Kernel *menu. No need to restart notebooks when switching kernels.

Let’s say you have created two custom environments in Anaconda, my_NLP, *and *gym. To add these in your Jupyter Notebooks, follow the steps below,

# Stop and exit your Jupyter Notebook server first
# Activate your environment in the terminal 
conda activate my_NLP
# Install the IPython Kernel 
pip install ipykernel
# Link your environment with Jupyter 
python -m ipykernel install --user --name=my_NLP
# Repeat steps for the other environment, gym. 
conda activate gym
pip install ipykernel 
python -m ipykernel install --user --name=gym

Now open your Jupyter Notebooks, go to the *Change Kernel *option in the *Kernel *menu and ….Boom! You should be able to see all the kernels listed there and you can now activate them simply by clicking on them.

This is where the newly added Kernels should show up. Notice the soothing midnight blue theme.

For all the other cool features I mentioned above, we need to install something called nbextensions for Jupyter Notebooks. Installing nbextensions is easy, simply follow the steps below,

# Stop and exit your Jupyter Notebook server 
# Make sure you are in the base environment
conda activate base

# Install the nbextensions 
pip install jupyter_contrib_nbextensions
# Install the necessary JS and CSS files 
jupyter contrib nbextension install --system

Start the Jupyter Notebook server and you should now see a fourth option called *Nbextensions *in the opening page. Click on it to see an awesome set of features that you always wanted in Jupyter Notebooks.

The Nbextensions tab!

As you can see above, the list of extensions is huge and even a little intimidating at first sight. Not all of them are useful, and here are the ones that I use,

  1. Table of Contents(2) — *Generate a *table of contents for the entire notebook in a single click, with hyperlinks to various sections.
  2. *Scratchpad — *Absolutely the best extension in my opinion. A separate space for you to experiment with code without disturbing the rest of the notebook.
  3. *Codefolding — *No need for any explanation here.
  4. *Hide Input All — *Hide all the code cells, while leaving the output and markdown cells visible. A very useful feature if you are trying to explain your results to non-technical people.
  5. *Variable Inspector — *To save you from the debugging blues, something similar to the variable inspector window found in Spyder IDE.
  6. *Spellchecker — *A spell checker for the content in your markdown cells.
  7. *Zenmode — *Removes extra clutter from the screen so that you can focus on what is important, the code.
  8. *Snippets Menu — *A cool collections of frequently used code snippets from list comprehensions to pandas and everything in-between. Best Part? You can modify the widget and add your own custom snippets.

The above list contains the extensions that I mostly use, but you’re encouraged to try out the rest. Some interesting ones include ScrollDown,table_beautifier, and Hinterland.

The Snippets extension in action along with the Table of Contents generation extension at work.

The Scratchpad extension

Let me know what do you think about these enhancements for Jupyter Notebooks. If you face any errors in installing the extensions, feel free to drop in a comment.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Top 12 Python Libraries for Machine Learning and Data Science in 2020

Python has been the go-to choice for Machine Learning, Data Science and Artificial Intelligence developers for a long time. Python libraries for modern machine learning models & projects: TensorFlow; Numpy; Scipy; Scikit-learn; Theano; Keras; PyTorch; Pandas; Matplotlib; ...

Machine Learning, Data Science and Deep Learning with Python

Complete hands-on Machine Learning tutorial with Data Science, Tensorflow, Artificial Intelligence, and Neural Networks. Introducing Tensorflow, Using Tensorflow, Introducing Keras, Using Keras, Convolutional Neural Networks (CNNs), Recurrent Neural Networks (RNNs), Learning Deep Learning, Machine Learning with Neural Networks, Deep Learning Tutorial with Python

Python For Data Science - How to use Data Science with Python

This Edureka video on 'Python For Data Science - How to use Data Science with Python - Data Science using Python ' will help you understand how we can use python for data science along with various use cases. What is Data Science? Why Python? Python Libraries For Data Science. Roadmap To Data Science With Python. Data Science Jobs and Salary Trends