0% found this document useful (0 votes)
243 views12 pages

15 Tips and Tricks Jupyter Notebook

This document discusses 15 tips and tricks for optimizing work in the Jupyter Notebook. Some of the tips include calculating cell execution time, using progress bars, automatically formatting code, installing packages within notebooks, accessing documentation via tab completion, adjusting output views, running code from different languages, creating presentations from notebooks, and customizing keyboard shortcuts. Jupyter Notebook allows interactive coding in a browser and these tricks can enhance the user experience.

Uploaded by

Evelyn Ortiz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
243 views12 pages

15 Tips and Tricks Jupyter Notebook

This document discusses 15 tips and tricks for optimizing work in the Jupyter Notebook. Some of the tips include calculating cell execution time, using progress bars, automatically formatting code, installing packages within notebooks, accessing documentation via tab completion, adjusting output views, running code from different languages, creating presentations from notebooks, and customizing keyboard shortcuts. Jupyter Notebook allows interactive coding in a browser and these tricks can enhance the user experience.

Uploaded by

Evelyn Ortiz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

15 Tips and Tricks for Jupyter Notebook that will ease

your Coding Experience


towardsdatascience.com/15-tips-and-tricks-for-jupyter-notebook-that-will-ease-your-coding-experience-e469207ac95c

Optimize your work in Jupyter Notebook using these hacks

Image by from

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.

1. Calculate the time of execution of a cell:


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.

1/12
2. Progress Bar:
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:

3. Automatic Code Formatter:


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:

2/12
pip3 install nb_black

Usage for Jupyter Notebook:

%load_ext nb_black

(Image by Author), Unformatted cell

(Image by Author), Formatted cell using nb_black

4. Install Packages:
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.

5. Documentation:
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

3/12
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.

(Image by Author), Docstring for the pandas read_csv function

6. Autocomplete:
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.

4/12
(Image by Author), Suggestions from the pandas
package

7. Adjust the view of Output:


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.

(Gif by Author), Click on the left side of the panel to change the view of the output screen

8. Cell Execution Features:

5/12
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.

9. Markdown:
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

(Image by Author), Covert code cell to markdown cells

6/12
()

10. Run code from different languages in the notebook:


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

(Image by Author), HTML code snippet in jupyter notebook cell

7/12
11. Multiple Cursor:
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.

12. Creating Presentation from Jupyter Notebook:


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 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.

8/12
()

13. Share Jupyter Notebooks:


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 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 to know the steps.

9/12
14. Plotting in Notebook:
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:

(), Different types of plots

15. Keyboard Shortcuts:


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 .

10/12
(Image by Author), Command Mode Keyboard Shortcuts

(Image by Author), Edit Mode Keyboard Shortcuts

11/12
Conclusion:
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.

Thank You for Reading

12/12

You might also like