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.mzph.cn/news/389602.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!