JupyterNotebook的15个技巧和窍门,可简化您的编码体验
写给幼儿园老师的话JupyterNotebook的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笔记本计算机单元的执⾏时间。 它计算墙壁时间 ,可以将其称为执⾏该单元所需的总时间。
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 .
可以使⽤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函数,其⽤法和实现如下所⽰:
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 by Author), Unformatted cell
(作者提供的图⽚),未格式化的单元格
(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并运⾏单元。
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.
单击⽂档右上⾓的^以在寻呼机中查看它。
造梦西游3宠物怎么抓Click on + to grow the docstring vertically.
单击+垂直增加⽂档字符串。
Click on x to close the docstring.
单击x关闭⽂档字符串。
(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-up或arrow-down键向上或向下滚动菜单。 您也
可以使⽤⿏标滚动。 单击关键字或在选定的关键字上按Enter键以确认您的建议。
You will also get suggestions for custom functions and variables.
您还将获得有关⾃定义函数和变量的建议。
(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.
您可以重复单击或双击的过程来更改查看输出⾯板的格式。
(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
(作者提供的图⽚),隐式代码单元到降价单元
) )
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

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。