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.mzph.cn/news/389602.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

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盏灯,你需要在每个房间里放入一盏灯。每盏灯都有一定功率,每间房间都需要不少于一定功率的灯泡才可以完全照亮。 你可以去附近的商店换新灯泡,商店里所有正整数功率的灯泡都有售。但由于背包空间有限,你…

WPF绑定资源文件错误(error in binding resource string with a view in wpf)

报错:无法将“***Properties.Resources.***”StaticExtension 值解析为枚举、静态字段或静态属性 解决办法:尝试右键单击在Visual Studio解决方案资源管理器的资源文件,并选择属性选项,然后设置自定义工具属性 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.这是本系列的第六篇文章,我们将通过Judea Pearl本人与他人合着的《引诱统计学…

如何优化网站加载时间

一、背景 我们要监测网站的加载情况,可以使用 window.performance 来简单的检测。 window.performance 是W3C性能小组引入的新的API,目前IE9以上的浏览器都支持。一个performance对象的完整结构如下图所示: memory字段代表JavaScript对内存的…

熊猫数据集_处理熊猫数据框中的列表值

熊猫数据集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.您是否曾经处理过需要使用列表值的数据集? 如果是这样&#xff0…

旋转变换(一)旋转矩阵

1. 简介 计算机图形学中的应用非常广泛的变换是一种称为仿射变换的特殊变换,在仿射变换中的基本变换包括平移、旋转、缩放、剪切这几种。本文以及接下来的几篇文章重点介绍一下关于旋转的变换,包括二维旋转变换、三维旋转变换以及它的一些表达方式&#…

数据预处理 泰坦尼克号_了解泰坦尼克号数据集的数据预处理

数据预处理 泰坦尼克号什么是数据预处理? (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全连接层(线性层) 计算公式: y w * x b W和b是参与训练的参数 W的维度决定了隐含层输出的维度,一般称为隐单元个数(hidden size) b是偏差值(本文没考虑) 举例: 输…

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

2019独角兽企业重金招聘Python工程师标准>>> IDEA版本 2017.3 mapper.xml文件中的sql语句,总是黄色一大片,看起来不舒服。 按如下设置进行设置即可 此时设置完还有点背景色 再进行一个设置 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.散点图…

Pytorch中RNN入门思想及实现

RNN循环神经网络 整体思想: 将整个序列划分成多个时间步,将每一个时间步的信息依次输入模型,同时将模型输出的结果传给下一个时间步,也就是说后面的结果受前面输入的影响。 RNN的实现公式: 个人思路: 首…

小扎不哭!FB又陷数据泄露风波,9000万用户受影响

对小扎来说,又是多灾多难的一个月。 继不久前Twitter曝出修补了一个可能造成数以百万计用户私密消息被共享给第三方开发人员的漏洞,连累Facebook股价跟着短线跳水之后,9月28日,Facebook又双叒叕曝出因安全漏洞遭到黑客攻击&#…

在衡量欧洲的政治意识形态时,调查规模的微小变化可能会很重要

(Related post: On a scale from 1 to 10, how much do the numbers used in survey scales really matter?)(相关文章: 从1到10的量表,调查量表中使用的数字到底有多重要? ) At Pew Research Center, survey questions about respondents’…

Pytorch中CNN入门思想及实现

CNN卷积神经网络 基础概念: 以卷积操作为基础的网络结构,每个卷积核可以看成一个特征提取器。 思想: 每次观察数据的一部分,如图,在整个矩阵中只观察黄色部分33的矩阵,将这【33】矩阵(点乘)权重得到特…

事件映射 消息映射_映射幻影收费站

事件映射 消息映射When I was a child, I had a voracious appetite for books. I was constantly visiting the library and picking new volumes to read, but one I always came back to was The Phantom Tollbooth, written by Norton Juster and illustrated by Jules Fei…

前端代码调试常用

转载于:https://www.cnblogs.com/tabCtrlShift/p/9076752.html

Pytorch中BN层入门思想及实现

批归一化层-BN层(Batch Normalization) 作用及影响: 直接作用:对输入BN层的张量进行数值归一化,使其成为均值为零,方差为一的张量。 带来影响: 1.使得网络更加稳定,结果不容易受到…

匿名内部类和匿名类_匿名schanonymous

匿名内部类和匿名类Everybody loves a fad. You can pinpoint someone’s generation better than carbon dating by asking them what their favorite toys and gadgets were as a kid. Tamagotchi and pogs? You were born around 1988, weren’t you? Coleco Electronic Q…

Pytorch框架中SGD&Adam优化器以及BP反向传播入门思想及实现

因为这章内容比较多,分开来叙述,前面先讲理论后面是讲代码。最重要的是代码部分,结合代码去理解思想。 SGD优化器 思想: 根据梯度,控制调整权重的幅度 公式: 权重(新) 权重(旧) - 学习率 梯度 Adam…