Jupyter Notebook的15個技巧和竅門,可簡化您的編碼體驗

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筆記本計算機單元的執行時間。 它計算墻壁時間 ,可以將其稱為執行該單元所需的總時間。

Image for post

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筆記本電腦中!

Image for post

The tqdm function can be used by importing its package and the usage and implementation can be observed below:

可以通過導入其軟件包來使用tqdm函數,其用法和實現如下所示:

Image for post

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
Image for post
(Image by Author), Unformatted cell
(作者提供的圖片),未格式化的單元格
Image for post
(Image by Author), Formatted cell using nb_black
(作者提供的圖像),使用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并運行單元。

Image for post

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關閉文檔字符串。

Image for post
(Image by Author), Docstring for the pandas read_csv function
(作者提供的圖片),熊貓的string,read_csv函數

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-uparrow-down鍵向上或向下滾動菜單。 您也可以使用鼠標滾動。 單擊關鍵字或在選定的關鍵字上按Enter鍵以確認您的建議。

You will also get suggestions for custom functions and variables.

您還將獲得有關自定義函數和變量的建議。

Image for post
(Image by Author), Suggestions from the pandas package
(作者提供的圖片),來自熊貓包裝的建議

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.

您可以重復單擊或雙擊的過程來更改查看輸出面板的格式。

Image for post
(Gif by Author), Click on the left side of the panel to change the view of the output screen
(按作者顯示),點擊面板左側以更改輸出屏幕的視圖

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選項
Image for post
(Image by Author), Covert code cell to markdown cells
(作者提供的圖片),隱式代碼單元到降價單元
Image for post
Source)來源 )

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

Image for post
(Image by Author), HTML code snippet in jupyter notebook cell
(作者提供的圖片),jupyter筆記本單元格中HTML代碼段

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鍵,然后使用鼠標選擇代碼段。 選擇后,您現在可以一次使用多個光標編輯代碼。

Image for post

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.

請訪問此處以獲取詳細的視頻指南用法。

Image for post
Source)來源 )

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文件等。
Image for post
  • 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

    情節

Image for post
Source), Different types of plots來源 ),不同類型的地塊

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

Image for post
(Image by Author), Command Mode Keyboard Shortcuts
(作者提供的圖像),命令模式鍵盤快捷鍵
Image for post
(Image by Author), Edit Mode 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,一經查實,立即刪除!

相關文章

給定有權無向圖的鄰接矩陣如下,求其最小生成樹的總權重,代碼。

#include<bits/stdc.h> using namespace std; #define INF 0x3f3f3f3f const int maxn 117; int m[maxn][maxn]; int vis[maxn], low[maxn]; /* 對于這道題目來將&#xff0c;m就是臨接矩陣&#xff0c;vis是訪問標記數組&#xff0c;low是最短距離數組 */ int n; int …

Ubuntu-16-04-編譯-Caffe-SSD

該來的還是要來 之前為了偷懶想到使用 Docker 回避 Caffe SSD 編譯的難題。結果&#xff0c;「天道好輪回&#xff0c;蒼天饒過誰」。Docker 鏡像內無法調用 GUI 顯示以及攝像頭&#xff0c;沒法跑 ssd_pascal_webcam.py 做實時 Object Detection。所以沒辦法又得重新嘗試編譯 …

bi數據分析師_BI工程師和數據分析師的5個格式塔原則

bi數據分析師Image by Author圖片作者 將美麗融入數據 (Putting the Beauty in Data) Have you ever been ravished by Vizzes on Tableau Public that look like only magic could be in play to display so much data in such a pleasing way?您是否曾經被Tableau Public上的…

BSOJ 2423 -- 【PA2014】Final Zarowki

Description 有n個房間和n盞燈&#xff0c;你需要在每個房間里放入一盞燈。每盞燈都有一定功率&#xff0c;每間房間都需要不少于一定功率的燈泡才可以完全照亮。 你可以去附近的商店換新燈泡&#xff0c;商店里所有正整數功率的燈泡都有售。但由于背包空間有限&#xff0c;你…

WPF綁定資源文件錯誤(error in binding resource string with a view in wpf)

報錯&#xff1a;無法將“***Properties.Resources.***”StaticExtension 值解析為枚舉、靜態字段或靜態屬性 解決辦法&#xff1a;嘗試右鍵單擊在Visual Studio解決方案資源管理器的資源文件&#xff0c;并選擇屬性選項&#xff0c;然后設置自定義工具屬性 PublicResXFile cod…

因果推論第六章

因果推論 (Causal Inference) This is the sixth post on the series we work our way through “Causal Inference In Statistics” a nice Primer co-authored by Judea Pearl himself.這是本系列的第六篇文章&#xff0c;我們將通過Judea Pearl本人與他人合著的《引誘統計學…

如何優化網站加載時間

一、背景 我們要監測網站的加載情況&#xff0c;可以使用 window.performance 來簡單的檢測。 window.performance 是W3C性能小組引入的新的API&#xff0c;目前IE9以上的瀏覽器都支持。一個performance對象的完整結構如下圖所示&#xff1a; memory字段代表JavaScript對內存的…

VMWARE VCSA 6.5安裝過程

https://www.tech-coffee.net/step-by-step-deploy-vcenter-server-appliance-vcsa-6-5/ vcsa 6.0&#xff0c;6.5 注冊機下載 鏈接:https://pan.baidu.com/s/1X5V-iWpvxozrwE7Ji099jw 密碼:jt8l 轉載于:https://www.cnblogs.com/flyhgx/p/9073485.html

熊貓數據集_處理熊貓數據框中的列表值

熊貓數據集Have you ever dealt with a dataset that required you to work with list values? If so, you will understand how painful this can be. If you have not, you better prepare for it.您是否曾經處理過需要使用列表值的數據集&#xff1f; 如果是這樣&#xff0…

聊聊jdk http的HeaderFilter

序 本文主要研究一下jdk http的HeaderFilter。 FilterFactory java.net.http/jdk/internal/net/http/FilterFactory.java class FilterFactory {// Strictly-ordered list of filters.final LinkedList<Class<? extends HeaderFilter>> filterClasses new Linked…

旋轉變換(一)旋轉矩陣

1. 簡介 計算機圖形學中的應用非常廣泛的變換是一種稱為仿射變換的特殊變換&#xff0c;在仿射變換中的基本變換包括平移、旋轉、縮放、剪切這幾種。本文以及接下來的幾篇文章重點介紹一下關于旋轉的變換&#xff0c;包括二維旋轉變換、三維旋轉變換以及它的一些表達方式&#…

數據預處理 泰坦尼克號_了解泰坦尼克號數據集的數據預處理

數據預處理 泰坦尼克號什么是數據預處理&#xff1f; (What is Data Pre-Processing?) We know from my last blog that data preprocessing is a data mining technique that involves transforming raw data into an understandable format. Real-world data is often incom…

Pytorch中DNN入門思想及實現

DNN全連接層&#xff08;線性層&#xff09; 計算公式&#xff1a; y w * x b W和b是參與訓練的參數 W的維度決定了隱含層輸出的維度&#xff0c;一般稱為隱單元個數&#xff08;hidden size&#xff09; b是偏差值&#xff08;本文沒考慮&#xff09; 舉例&#xff1a; 輸…

IDEA去除mapper.xml文件中的sql語句的背景色

2019獨角獸企業重金招聘Python工程師標準>>> IDEA版本 2017.3 mapper.xml文件中的sql語句&#xff0c;總是黃色一大片&#xff0c;看起來不舒服。 按如下設置進行設置即可 此時設置完還有點背景色 再進行一個設置 Ok,完美解決 轉載于:https://my.oschina.net/u/3939…

vc6.0 繪制散點圖_vc有關散點圖的一切

vc6.0 繪制散點圖Scatterplots are one of the most popular visualization techniques in the world. Its purposes are recognizing clusters and correlations in ‘pairs’ of variables. There are many variations of scatter plots. We will look at some of them.散點圖…

sudo配置臨時取得root權限

sudo配置臨時取得root權限系統中的普通用戶有時需要root權限執行某種操作&#xff0c;要是使用su - root的話必須要知道root的密碼&#xff0c;這是不安全的&#xff0c;所以有了sudo&#xff0c;root可以對/etc/sudoers做一定的配置&#xff0c;讓普通用戶在不切換到root的情況…

Pytorch中RNN入門思想及實現

RNN循環神經網絡 整體思想&#xff1a; 將整個序列劃分成多個時間步&#xff0c;將每一個時間步的信息依次輸入模型&#xff0c;同時將模型輸出的結果傳給下一個時間步&#xff0c;也就是說后面的結果受前面輸入的影響。 RNN的實現公式&#xff1a; 個人思路&#xff1a; 首…

小扎不哭!FB又陷數據泄露風波,9000萬用戶受影響

對小扎來說&#xff0c;又是多災多難的一個月。 繼不久前Twitter曝出修補了一個可能造成數以百萬計用戶私密消息被共享給第三方開發人員的漏洞&#xff0c;連累Facebook股價跟著短線跳水之后&#xff0c;9月28日&#xff0c;Facebook又雙叒叕曝出因安全漏洞遭到黑客攻擊&#…

在衡量歐洲的政治意識形態時,調查規模的微小變化可能會很重要

(Related post: On a scale from 1 to 10, how much do the numbers used in survey scales really matter?)(相關文章&#xff1a; 從1到10的量表&#xff0c;調查量表中使用的數字到底有多重要&#xff1f; ) At Pew Research Center, survey questions about respondents’…

Pytorch中CNN入門思想及實現

CNN卷積神經網絡 基礎概念&#xff1a; 以卷積操作為基礎的網絡結構&#xff0c;每個卷積核可以看成一個特征提取器。 思想&#xff1a; 每次觀察數據的一部分&#xff0c;如圖&#xff0c;在整個矩陣中只觀察黃色部分33的矩陣&#xff0c;將這【33】矩陣(點乘)權重得到特…