15 Tips and Tricks for Jupyter Notebook that will ease your Coding Experience | by Satyam Kumar | Towards Data Science

Jupyter Notebook is a browser bases REPL (read eval print loop) built on IPython and other open-source libraries, it allows us to run interactive python code on the browser.
It not only runs python code but also has many interesting plugins and magic commands which enhances the python coding experience greatly.
One can calculate the time of execution of a jupyter notebook cell using magic command at the beginning of the cell. It calculates the wall time that can be referred to as the total time required to execute that cell.
One can use a python external library to create a progress bar, that can give live updates of the progress of code. It keeps the user informed about the status of a running code script. You can get the Github repository of library here.
First, you need to install tqdm library,
pip3 install tqdm
Or you can also install it in a jupyter notebook cell using ! .
The tqdm function can be used by importing its package and the usage and implementation can be observed below:
Using nb_black library, one can format a code snippet in a cell to a proper format. Sometimes the code snippet in a jupyter notebook cell is not well-formatted, this library helps to attain proper formatting of the code snippet.
nb_black is a simple extension for Jupyter Notebook and Jupyter Lab to beautify Python code automatically.
Installation of the library:
pip3 install nb_black
Usage for Jupyter Notebook:
%load_ext nb_black
Jupyter Notebook can install any python package in the notebook itself. To install any python package using the pip command in jupyter notebook cell enter a ! before the command.
For installing the pandas package: Enter ! pip install pandas and run the cell.
Jupyter Notebook can show that documentation of the function you are calling. Press Shift+Tab to view the documentation. This is very helpful as you don’t need to open the documentation website every single time. This feature also works for the local custom functions.
Usage:
Write the name of the function you want to implement
Press Shift+Tab to view the documentation.
Click on ^ on the top right corner of documentation to view it in a pager.
Click on + to grow the docstring vertically.
Click on x to close the docstring.
Jupyter Notebook can show suggestions for any function name or variable. To view suggestions writing typing the code press Tab in your keyboard and the suggestion will appear in a top-down menu. Press arrow-up or arrow-down key to scroll up or down the menu. You can also scroll using your mouse. Click on the keyword or hit enter on the selected keyword to confirm your suggestion.
You will also get suggestions for custom functions and variables.
Jupyter Notebook can print the output of each cell just below the cell. When you have a lot of output you can reduce the amount of space it takes up by clicking on the left side panel of the output. This will turn the output into a scrolling window. Double click on the left side of the output to completely collapse the output panel.
You can repeat the process of a single click or double click to change the format of viewing the output panel.
Jupyter Notebook has certain cell execution features that ease the programmer’s performance.
Shit+Enter will run the current cell and highlight the next cell, if no cell is present it will create a new cell.
Alt+Enter will run the current cell and insert a new cell and highlight it.
Jupyter notebook cells can not only run code snippets but also be used to write text. Markdown cells can be used to write text descriptions. It is a better way to express than using comments.
Usage:
Click on the cell to convert it to markdown.
Choose the Markdown option from the drop-down menu
Jupyter Notebook cells can also be used to compile and run code from different languages using IPython magic commands. Use IPython Magics with the name of your kernel at the start of each cell that you want to use that cell for:
%%bash
%%HTML
%%python2
%%python3
%%ruby
%%perl
Jupyter Notebook supports editing code using multiple cursors at once. To select the code to edit at once press Alt key and select the code snippet using your mouse. After selection, you can now edit the code using multiple cursors at once.
Jupyter Notebook can be used to create a PowerPoint-style presentation. Here each cell or group of cells of the notebook can be treated as each slide.
Firstly, install RISE using conda: conda install -c damianavila82 rise
Enter/Exit RISE Slideshow button appears in the notebook toolbar. A slideshow option will also appear under View>Cell Toolbar>Slideshow
To prepare Slideshow click on View>Cell Toolbar>Slideshow and select the jupyter notebook cells for each slide.
After selecting each slide click on the RISE Slideshow button in the notebook toolbar.
Visit here for detailed video guide usage.
After code completion, you have several options to share your jupyter notebook.
Download your jupyter notebook as HTML, pdf, ipynb, py file, etc.
You can use JupyterHub that can create a multi-user Hub which spawns, manages, and proxies multiple instances of the single-user Jupyter notebook server.
You can publish to medium directly from the jupyter notebook. Read this to know the steps.
Jupyter Notebook is the best tool used for data analysis and visualization. It can be used to generate different types of plots using different python or R libraries. Some of the python libraries used to generate plots are:
Matplotlib
Seaborn
bokeh
plot.ly
Shortcuts are used to save a lot of programmer’s time and ease the coding experience. Jupyter notebook has plenty of inbuilt keyboard shortcuts that you find under the Help menu bar: Help>Keyboard Shortcuts .
Jupyter Notebook also provides functionality to edit the keyboard shortcuts as per the programmer’s convenience. You can edit keyboard shortcuts: Help>Edit Keyboard Shortcuts .
Jupyter Notebook is one of the best tools extensible used by folks working in the data science domain due to interactive UI. The above-discussed 15 tips and tricks will help you to ease your jupyter notebook coding experience. It has a lot more built-in magic commands that are not discussed in this article, you can have a read here. Let me know your favorite tips and comment if know more tricks.
The images used in the article are either cited or generated by the author
Thank You for Reading