15 Jupyter Notebook skills you should master

Jupyter Notebook is a browser-based interactive programming environment (REPL, read eval print loop), which is mainly built on open source libraries such as IPython, allowing us to run interactive python code on the browser. And there are many interesting plug-ins and magical commands, which greatly enhance the python programming experience.

1. Calculation unit execution time

We can use %%timecommands at the beginning of a jupyter notebook unit to calculate the time to execute the unit.

2. Progress bar

You can use the python external library to create a progress bar, which can update the progress of the code in real time. It lets the user know the status of the running code script. You can get the related library Github library here . Use the progress bar to set, the specific operations are as follows:

First, install the tqdmlibrary:
enter it in the cmd command window pip3 install tqdmor directly in the jupyter notebook unit !pip install tqdm.

Then, the progress bar is generated by the following command:

3. Code format automatic completion

Sometimes the format of the code segment in the jupyter notebook cell is not good. Through the nb_blacklibrary, the correct format of the code segment can be automatically adjusted to make the code more readable.

Install the nb_blacklibrary:

pip3 install nb_black

Use in jupyter notebook:

%load_ext nb_black

Malformed code snippet

Auto-adjusted code snippet

4. Download and install the Python library

Jupyter notebook can !pip install ***automatically download and install the specified python library by entering the code in the cell .
Take the pandas library as an example, the specific code is as follows:

5. Function documentation

Through the shift+tabshortcut keys, you can directly open the documentation of the function in the jupyter notebook.

The specific usage is as follows:

  • Enter the function name used
  • Press shortcutshift+tab
  • Click the ^button in the pop-up window to display the documentation in the current window
  • Click +to control the text to slide down
  • Click xto close the documentation window

Documentation for the read_csv function in pandas

6. Code completion

Jupyter notebook can display suggestions for completion of any function name or variable. To view the completion suggestions, you can press the Tab key on the keyboard. The suggestions will appear in a top-down menu. Click the keyword or click the key on the selected keyword enterto confirm the completed code.

Completion suggestions for functions in pandas

7. Adjust the display window of the output result

Jupyter notebook can display the output below the code cell. When the user's output is too much, you can choose to adjust the size of the display window to adjust the display window to a rolling window. And double-click on the left side of the display window to collapse the window.

Adjust the display window

8. Unit running shortcuts

The programming efficiency can be improved through the following shortcut keys:

  • shift+enter Run the current unit and highlight the next unit. If there is no next unit, create a new unit.
  • alt+enter Run the current unit and insert a new unit and highlight it.

9. Markdown notes

Jupyter notebook cells can not only run code snippets, but also set the cells to Markdown to write text.

The conversion method is as follows:

  • Click on the target cell
  • Check the "Markdown" option

Cells are converted from code mode to Markdown mode

Markdown mode operation effect

10. Run different programming languages

Jupyter notebook can also be used to compile and run code from different languages. Just enter a %%****command at the beginning of the cell to run the ****corresponding language code:

  • %%bash
  • %%HTML
  • %%python2
  • %%python3
  • %%ruby
  • %%perl

Run HTML code in jupyter notebook cell

11. Edit multiple lines at the same time

Jupyter Notebook supports editing code with multiple cursors at the same time. After selecting the code segment to be edited with the alt key, you can use multiple cursors to edit the code at the same time.

12. Create a presentation

Jupyter notebook can be used to create PowerPoint-style presentations. Here, each cell or group of cells in the notebook can be regarded as a slide.

  • First, install the RISE library ( conda install -c damianavila82 rise)
  • After installation, RISE related buttons will be added to the toolbar (view->cell->toolbar->slideshow)
  • Select the cell to be displayed and set it as a slide
  • After selecting, click the RISE Sliedeshow button to complete the creation of the presentation document

13. Share Jupyter notebook

After the program code is written, Jupyter notebook provides multiple forms for users to share:

  • Share in HTML, PDF, ipynb, py and other file formats

  • Using JupyterHub, it can create a multi-user shared Hub that generates, manages and proxy users Jupyter notebook servers.

  • Upload directly to the network

14. Data presentation

Jupyter notebook can generate different charts through numerous python libraries and R language-related libraries. Commonly used libraries are:

  • Matplotlib
  • Seaborn
  • bokeh
  • plot.ly

Various chart styles

15. Shortcut keys

Using shortcuts can save programmers a lot of time and optimize programming experience. Jupyter notebook has many built-in keyboard shortcuts, which can be found under the "help" menu bar: "help">"Help>Keyboard Shortcuts".

Jupyter notebook also provides the function of editing keyboard shortcuts to facilitate programmers to personalize settings.

Shortcut key panel (command mode)

Shortcut panel (edit mode)

Author: Satyam Kumar

deephub translation team: Oliver Lee

Guess you like

Origin blog.csdn.net/m0_46510245/article/details/108689139