Hello, I am Xiao Wu 🧐

Earlier we shared 10 fun Jupyter Notebook tips and 5 Rubik’s Cube commands 👇

5 Tips for using the Notebook of Jupyter

5 Tips for using the Jupyter Notebook

5 Jupyter Notebook Magic commands (3rd shot)

Wouldn’t it be fun to spend a few minutes mastering some of these techniques to increase your productivity and save time?

Today is our fourth article about some interesting and useful Jupyter Notebook plug-ins.

Installing a plug-in

The previous articles have introduced some tips for using Jupyter, but the original Jupyter Notebook was still just a single editor. How do you make it more productive and closer to an IDE?

Fortunately, some developers already wrote a number of helper plugins for us in JavaScript. You can search for the jupyter_contrib_nbextensions plug-in on Github and just type two lines of commands as per the official documentation.

PIP install jupyter_nbextensionS_configurator enable Jupyter nbextensions_configurator enable --userCopy the code

Here are the steps to install the plugin:

1. Just like opening Jupyter Notebook, find Anaconda Prompt and click Open;

2. Type PIP install jupyter_contrib_nbextensions and click Enter, which may be a little slower.

Enter y and press Enter until the message Successfully Installed appears, as shown in the picture below. We then successfully installed the Jupyter_contrib_nbextensions module.

3. After the JUPyter_contrib_nbextensions module is installed, we need to continue typing Jupyter contrib nbextension install –user and press Enter to configure the user.

This will complete the installation

After installation, just re-enter the main page of Jupyter Notebook and you can see that the “NBextensions” option is added. Click to enter the option and select your favorite plug-in to improve your programming experience.

To add a plug-in, click the Nbextensions TAB to open and select the plug-in you want to add first.

If the plugin is all grey and unselectable, notice that the warning box is unchecked in the upper left corner (the circle in the image below).

Recommend a plug-in

Here are some practical Jupyter Notebook plug-ins that you can use to make it even more powerful.

directory

Add method:

Select Table of Contents(2) under Nbextensions option

Usage:

In the ipynb file of the first line of code we just created, we added a three-level title, and noticed that the main screen has a box button (arrow in the image below).

Click the button in the upper right corner of the box and the contents will be displayed.

Automatic completion

Add method:

Select Hinterland in the Nbextensions option

Usage:

Go back to the ipynb file and write print(” Hello world”) in the new code box. You will see that after one or two letters the system automatically selects the possible code/function for you.

In addition, we use autocomplete to quickly fill in print(), print() function usage and parameters are all out, really useful for beginners.

Of course, or suggest that we do more, commonly used functions or to remember and hand play.

Displays the running time and elapsed time

Add method:

Select ExecuteTime in the Nbextensions option

Usage:

Print (” Hello World “) in the new code box, and successfully display the completion time and the length of the code in the cell.

Beautify/format code

Add method:

Select Autopep8 in the Nbextensions option

Usage:

Autopep8, which reformats/beautifies the content of code cells with kernel-specific code.

Custom code blocks (code reuse)

Add method:

Select Snippets in the Nbextensions option

Usage:

When this extension is added, a drop-down menu appears in the toolbar. As shown in the figure below, we can easily insert some common codes into cells.

In everyday use, there are some pieces of code that need to be reused frequently. You can save your frequently used code snippets into the sample beforehand so you don’t have to type them every time.

Specific means is found in the install directory $(jupyter – data – dir)/nbextensions/Snippets/Snippets. JSON, then according to the existing in JSON code list to add a new JSON block to specify the code segment.

For example, to add a new snippet that imports numpy, matplotlib, and print statements, the JSON file should be modified to read:

{
    "snippets": [{"name" : "example"."code" : [
                "# This is an example snippet!"."# To create your own, add a new snippet block to the"."# snippets.json file in your jupyter data directory under nbextensions:"."# $(jupyter --data-dir)/nbextensions/snippets/snippets.json"."import this"] {},"name" : "some imports"."code" : [
                "import numpy as np"."import matplotlib as mpl"."print('spam')"]]}}Copy the code

So we’ll name the snippet we need to reuse some imports and add it to the Snippets. Next time we need to use, directly find the drop-down box, and click to insert.

Note: The plug-in snippet menu also works like a custom snippet, which is not covered here.

Today we continued our introduction to some of the extensions for Jupyter Notebook, so we’ve covered tips, magic commands, and plug-ins in four articles. Needless to say, Jupyter Notebook remains an integral part of the data science workflow. For those of us who use Jupyter Notebook as a regular tool, it’s important to use a variety of tricks to increase productivity.

Don’t forget to give this article a thumbs up at 👍 if you find some tips to increase your productivity/fun