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.
Jupyter Notebook是基于IPL和其他開源庫構建的基于REPL(讀取評估打印循環)的瀏覽器,它使我們能夠在瀏覽器上運行交互式python代碼。
It not only runs python code but also has many interesting plugins and magic commands which enhances the python coding experience greatly.
它不僅運行python代碼,還具有許多有趣的插件和魔術命令,從而極大地增強了python的編碼體驗。
1.計算單元執行時間: (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.
可以在單元格的開頭使用魔術命令來計算jupyter筆記本計算機單元的執行時間。 它計算墻壁時間 ,可以將其稱為執行該單元所需的總時間。

2.進度欄: (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.
可以使用python外部庫創建進度條,該進度條可以實時更新代碼進度。 它使用戶隨時了解正在運行的代碼腳本的狀態。 您可以在此處獲取Github庫信息庫。
First, you need to install tqdm
library,
首先,您需要安裝 tqdm
庫,
pip3 install tqdm
Or you can also install it in a jupyter notebook cell using !
.
或者,您也可以使用!
將其安裝在jupyter筆記本電腦中!
。

The tqdm
function can be used by importing its package and the usage and implementation can be observed below:
可以通過導入其軟件包來使用tqdm
函數,其用法和實現如下所示:

3.自動代碼格式化程序: (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
庫,可以將單元格中的代碼片段格式化為適當的格式。 有時,在jupyter筆記本電腦單元中的代碼段格式不正確,該庫有助于實現代碼段的正確格式。
nb_black
is a simple extension for Jupyter Notebook and Jupyter Lab to beautify Python code automatically.
nb_black
是Jupyter Notebook和Jupyter Lab的簡單擴展,可以自動美化Python代碼。
Installation of the library:
庫的安裝:
pip3 install nb_black
Usage for Jupyter Notebook:
Jupyter Notebook的用法:
%load_ext nb_black


4.安裝軟件包: (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.
Jupyter Notebook可以在筆記本本身中安裝任何python軟件包。 要在jupyter筆記本單元中使用pip命令安裝任何python軟件包,請輸入!
在命令之前。
For installing the pandas package: Enter ! pip install pandas
and run the cell.
要安裝pandas軟件包:輸入! pip install pandas
! pip install pandas
并運行單元。

5.說明文件: (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 functions.
Jupyter Notebook可以顯示您正在調用的函數的文檔。 按Shift+Tab
查看文檔。 這非常有用,因為您不需要每次都打開文檔網站。 此功能也適用于本地自定義功能。
Usage:
用法:
- Write the name of the function you want to implement 寫下您要實現的函數的名稱
Press
Shift+Tab
to view the documentation.按
Shift+Tab
查看文檔。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.單擊
x
關閉文檔字符串。

6.自動完成: (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.
Jupyter Notebook可以顯示有關任何函數名稱或變量的建議。 要查看鍵入代碼的建議,請按鍵盤上的Tab
鍵,該建議將顯示在自上而下的菜單中。 按arrow-up
或arrow-down
鍵向上或向下滾動菜單。 您也可以使用鼠標滾動。 單擊關鍵字或在選定的關鍵字上按Enter鍵以確認您的建議。
You will also get suggestions for custom functions and variables.
您還將獲得有關自定義函數和變量的建議。

7.調整輸出視圖: (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.
Jupyter Notebook可以在單元格正下方打印每個單元格的輸出。 當您有很多輸出時,可以通過單擊輸出的左側面板來減少占用的空間。 這會將輸出轉換為滾動窗口。 雙擊輸出的左側以完全折疊輸出面板。
You can repeat the process of a single click or double click to change the format of viewing the output panel.
您可以重復單擊或雙擊的過程來更改查看輸出面板的格式。

8.單元執行功能: (8. Cell Execution Features:)
Jupyter Notebook has certain cell execution features that ease the programmer’s performance.
Jupyter Notebook具有某些單元執行功能,可減輕程序員的性能。
- Shit+Enter will run the current cell and highlight the next cell, if no cell is present it will create a new cell. Shit + Enter將運行當前單元格并突出顯示下一個單元格,如果不存在任何單元格,則會創建一個新單元格。
- Alt+Enter will run the current cell and insert a new cell and highlight it. Alt + Enter將運行當前單元格并插入一個新單元格并突出顯示它。
9.降價: (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.
Jupyter筆記本單元不僅可以運行代碼段,還可以用于編寫文本。 Markdown單元格可用于編寫文本描述。 與使用注釋相比,這是一種更好的表達方式。
Usage:
用法:
- Click on the cell to convert it to markdown. 單擊單元格以將其轉換為降價。
- Choose the Markdown option from the drop-down menu 從下拉菜單中選擇Markdown選項


10.在筆記本中運行來自不同語言的代碼: (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:
Jupyter Notebook單元還可以用于使用IPython magic命令編譯和運行來自不同語言的代碼。 在每個要用于該單元格的單元格的開頭,將IPython Magics與內核名稱一起使用:
%%bash
%%bash
%%HTML
%%HTML
%%python2
%%python2
%%python3
%%python3
%%ruby
%%ruby
%%perl
%%perl

11.多光標: (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.
Jupyter Notebook支持一次使用多個光標編輯代碼。 要立即選擇要編輯的代碼,請按Alt
鍵,然后使用鼠標選擇代碼段。 選擇后,您現在可以一次使用多個光標編輯代碼。

12.從Jupyter Notebook創建演示文稿: (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.
Jupyter Notebook可用于創建PowerPoint樣式的演示文稿。 在這里,筆記本的每個單元格或單元格組都可以視為每個幻燈片。
Firstly, install RISE using conda:
conda install -c damianavila82 rise
首先,使用
conda install -c damianavila82 rise
安裝RISE :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 輸入/退出RISE幻燈片顯示按鈕出現在筆記本工具欄中。 幻燈片選項也會出現在“視圖”>“單元格工具欄”>“幻燈片”下
- To prepare Slideshow click on View>Cell Toolbar>Slideshow and select the jupyter notebook cells for each slide. 要準備幻燈片,請單擊“視圖”>“單元格工具欄”>“幻燈片”,然后為每張幻燈片選擇jupyter筆記本單元。
- After selecting each slide click on the RISE Slideshow button in the notebook toolbar. 選擇每張幻燈片后,單擊筆記本工具欄中的“ RISE幻燈片”按鈕。
Visit here for detailed video guide usage.
請訪問此處以獲取詳細的視頻指南用法。

13.共享Jupyter筆記本: (13. Share Jupyter Notebooks:)
After code completion, you have several options to share your jupyter notebook.
代碼完成后,您可以選擇幾種方式來共享jupyter筆記本。
- Download your jupyter notebook as HTML, pdf, ipynb, py file, etc. 將您的jupyter筆記本下載為HTML,pdf,ipynb,py文件等。

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.
您可以使用JupyterHub創建一個多用戶集線器,該中心可以生成,管理和代理單用戶Jupyter筆記本服務器的多個實例。
You can publish to medium directly from the jupyter notebook. Read this to know the steps.
您可以直接從jupyter筆記本發布到中型媒體。 閱讀本文以了解步驟。
14.在筆記本中繪圖: (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:
Jupyter Notebook是用于數據分析和可視化的最佳工具。 它可以用于使用不同的python或R庫生成不同類型的圖。 用于生成圖的一些python庫是:
Matplotlib
Matplotlib
Seaborn
Seaborn
bokeh
散景
plot.ly
情節

15.鍵盤快捷鍵: (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具有許多內置的鍵盤快捷鍵,您可以在“ Help
菜單欄下找到:“ 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還提供了根據程序員的方便來編輯鍵盤快捷鍵的功能。 您可以編輯鍵盤快捷鍵: Help>Edit Keyboard Shortcuts
。


結論: (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.
由于交互式UI,Jupyter Notebook是數據科學領域的人們使用的最佳可擴展工具之一。 上面討論的15個技巧和竅門將幫助您減輕Jupyter筆記本的編碼體驗。 它具有許多內置的魔術命令,本文不會討論,您可以在此處閱讀。 讓我知道您最喜歡的技巧,如果有更多技巧,請發表評論。
The images used in the article are either cited or generated by the author
本文中使用的圖像由作者引用或生成
Thank You for Reading
謝謝您的閱讀
翻譯自: https://towardsdatascience.com/15-tips-and-tricks-for-jupyter-notebook-that-will-ease-your-coding-experience-e469207ac95c
本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。 如若轉載,請注明出處:http://www.pswp.cn/news/389602.shtml 繁體地址,請注明出處:http://hk.pswp.cn/news/389602.shtml 英文地址,請注明出處:http://en.pswp.cn/news/389602.shtml
如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!