The Jupyter Notebook
is a different type of IDE
. It provides a lightweight interface that allows a user to create and interact with code in a neat and tidy way: the goal here being a report-style format, rather than core functionality.
Jupyter Notebook
是另一种类型的IDE
。 它提供了一个轻量级的界面,允许用户以整洁的方式创建代码并与之交互:这里的目标是报告样式的格式,而不是核心功能。
Now traditional IDE’s
would utilise some text file or some form of script
(in its rawest form) and a compiler
would run through the script
all at once but the goal of a Notebook
is to get results and visualise things as you go along. This work is generally synonymous with research projects.
现在,传统的IDE's
将利用某些文本文件或某种形式的script
(以其最原始的形式),并且compiler
将一次运行所有script
,但是Notebook
的目标是在运行过程中获得结果并可视化事物。 这项工作通常是研究项目的代名词。
When you download and install Python
, it’s accompanied with a cutesy and simple IDE
called IDLE
. However, it’s functionalities lack and you go in one of two directions — to a more production ready type of IDE
like PyCharm
or VSCode
, or, you go in a more research direction like Notebooks
.
当您下载并安装Python
,它会附带一个名为IDLE
的可爱,简单的IDE
。 但是,它缺乏功能,您会选择两个方向之一-转向更易于生产的IDE
类型(例如PyCharm
或VSCode
,或者,您会转向更研究的方向(例如Notebooks
。
If you use Python
regularly then I don’t need to sell you the reasons behind wanting to use such a great piece of kit, but instead below, below I’ll give a quick tutorial on how to use it.
如果您定期使用Python
,那么我不需要向您出售希望使用如此出色的工具包的原因,但是在下面的下面,我将为您提供有关如何使用它的快速教程。
The goal of a Jupyter Notebook
is to create an open source document where the code and its output can be displayed together. You can add formulas, figures, graphs, charts etc in the same document. Each Notebook
can also be shared with other people to make it easier to collaborate and explain any research.
Jupyter Notebook
的目标是创建一个开放源代码文档,其中的代码及其输出可以一起显示。 您可以在同一文档中添加公式,图形,图形,图表等。 每个Notebook
也可以与其他人共享,以简化协作和解释任何研究。
Let’s go through Notebooks
using an Anaconda
Installation.
我们来看看使用Anaconda
安装的Notebooks
。
启动笔记本 (Starting the Notebook)
Open your Anaconda
interface and select on Jupyter Notebooks
. A new tab in your browser will open and the screen will look like the below. This page is going to be a sight that you should get used to — a place that’s your central location to all your files and projects.
打开Anaconda
界面,然后在Jupyter Notebooks
上选择。 浏览器中的新标签页将打开,屏幕如下图所示。 您应该习惯了该页面的外观-这个位置是所有文件和项目的中心位置。
Now, when you look at that the right hand corner of the screen and click on ‘New
’, a list of items come out in the menu (as below) and to open a new Notebook
, you just click ‘Python 3
’ or whatever is your most recent version.
现在,当您查看屏幕的右上角并单击“ New
”时,菜单中会出现一个项目列表(如下所示),并打开一个新的Notebook
,您只需单击“ Python 3
”或其他按钮即可是您的最新版本。
The new opened notebook
will look something like the below screenshot.
新打开的notebook
将如下图所示。
The first thing you should do is click ‘Untitled’ at the top of the page and this allows you to rename your notebook
. Remember, as Jupyter Notebooks
is built on top of iPython
so all the Notebook files will end with .ipynb
.
您应该做的第一件事是单击页面顶部的“无标题”,这使您可以重命名notebook
。 记住, Jupyter Notebooks
是建立在之上iPython
,这样所有的笔记本电脑文件将结束.ipynb
。
了解笔记本 (Understanding the Notebook)
Now that we’re in a position where the notebook
is open we can focus on two key terms: Kernels
and Cells
.
现在我们处于打开notebook
的位置,我们可以集中讨论两个关键术语: Kernels
和Cells
。
A kernel
can be considered as the ‘computational engine’ in the system. It’s the backend system which executes the notebooks: think of it as the engine that drives the car. In this instance, the notebooks is the car (so the interior, the steering wheel, the radio), but the ‘kernel’ is the engine driving the whole thing. Note that the kernel exists in the background and doesn’t really interfere with you as a programmer. If you want to re-start your notebook (if it crashes or something), then you’d need to restart your kernel.
kernel
可以视为系统中的“计算引擎”。 它是执行笔记本电脑的后端系统:将其视为驱动汽车的引擎。 在这种情况下,笔记本是汽车(因此是内部,方向盘,收音机),但“内核”是驱动整个事情的引擎。 请注意,内核存在于后台,并且实际上不会干扰您作为程序员。 如果您想重新启动笔记本电脑(如果笔记本电脑崩溃或其他原因),则需要重新启动内核。
On the other hand, a cell is an area that you see on the notebook. It’s that grey’ed out area and can be considered a container of text or code. The easiest way to get to grips with it is to try it out. In the very first cell, type in the code:
另一方面,单元格是您在笔记本电脑上看到的区域。 它是灰色的区域,可以视为文本或代码的容器。 掌握它的最简单方法是尝试一下。 在第一个单元格中,输入代码:
print(“Hello World!!!!”)
and then press the shortcut shift
+enter
. Your result should be similar to the below screenshot.
然后按快捷键shift
+ enter
。 您的结果应类似于以下屏幕截图。
After we write code in the code cell, we can also click the play
button which executes the code in that cell and the output is shown in the markdown cell beneath it, indicated with Black tick mark in the screenshot above.
在代码单元格中编写代码后,我们还可以单击执行该单元格中的代码的play
按钮,输出将显示在其下方的markdown单元格中,在上面的屏幕快照中以黑色对勾表示。
The ln [1]:
indicates nothing but the line number in the screenshot. If we run another code in the next code cell, it will be In [2]
.
ln [1]:
表示屏幕截图中的行号。 如果我们在下一个代码单元中运行另一个代码,它将在In [2]
。
When running a code, you may notice that the border of the executing cell turns to Blue. This is because the cell is in “Command Mode” at that time. When not executing, the cell colour is Green which denotes “Edit Mode”.
运行代码时,您可能会注意到执行单元的边框变为蓝色。 这是因为该单元当时处于“命令模式”。 不执行时,单元格颜色为绿色,表示“编辑模式”。
Generally, the flow of a notebook
is from top to bottom but if we need to make a change in a previous cell or re-order the execution or reset things, then the kernel
menu is very useful. There are options like Restart and Clear Output
, Restart and Run All
, Interrupt
etc.
通常, notebook
的流程是从上到下的,但是如果我们需要在上一个单元格中进行更改或重新排列执行顺序或重置内容,则kernel
菜单将非常有用。 有诸如Restart and Clear Output
, Restart and Run All
, Interrupt
等选项。
There is also an option to Change Kernel
whereby the coder can switch the kernel
being used. Now as Python
is installed locally, my notebooks can only choose a Python Kernel
but if you had other languages
installed, you would get the option to use them here (instead of Python
).
还有一个“ Change Kernel
选项,编码人员可以通过该选项切换正在使用的kernel
。 现在,由于Python
是本地安装的,所以我的笔记本只能选择一个Python Kernel
但是如果您安装了其他languages
,则可以选择在此处使用它们(而不是Python
)。
在单元格中单击时的快捷方式 (Shortcuts when you’re click in a cell)
Alt + Enter
run the current cell, insert belowAlt + Enter
运行当前单元格,在下面插入Ctrl + S
save and checkpointCtrl + S
保存并检查点Shift + Enter
run the current cell, select belowShift + Enter
运行当前单元格,在下面选择Ctrl + Enter
run selected cellsCtrl + Enter
运行选定的单元格
在命令模式下(单击单元格,然后按Esc激活): (While in command mode (click on a cell, then press Esc to activate):)
Enter
take you into edit modeEnter
将您带入编辑模式H
show all shortcutsH
显示所有快捷方式Up
select cell aboveUp
选择上方的单元格Down
select cell belowDown
下面选择单元格Shift + Up
extend selected cells aboveShift + Up
将所选单元格扩展到上方Shift + Down
extend selected cells belowShift + Down
扩展下面的选定单元格A
insert cell above上方
A
插入单元格B
insert cell belowB
下方的插入单元格X
cut selected cellsX
剪切选定的单元格S
Save and CheckpointS
保存和检查点Y
change the cell type to CodeY
将单元格类型更改为CodeM
change the cell type to MarkdownM
将单元格类型更改为MarkdownP
open the command palette.P
打开命令面板。C
copy selected cellsC
复制选定的单元格V
paste cells belowV
在下面粘贴单元格Shift + V
paste cells aboveShift + V
粘贴上方的单元格D, D (press the key twice)
delete selected cellsD, D (press the key twice)
删除所选单元格Z
undo cell deletionZ
undo细胞缺失
And there you have it! The above article goes over a basic introduction on how to use Jupyter Notebooks
for absolute beginners, with a few tricks to keep you going.Notebooks
has been a lifeline to me and my research has been able to accelerate exponentially by virtue of having such a great tool. I really recommend to people who want to research to use Jupyter Notebooks
: you’ll never look back!
在那里,您拥有了! 上面的文章介绍了如何为绝对初学者使用Jupyter Notebooks
的基本介绍,并提供了一些技巧来帮助您继续前进。 Notebooks
一直是我的命脉,而拥有如此出色的工具使我的研究得以成倍地加速。 我真的向想要研究使用Jupyter Notebooks
人推荐:您永远不会回头!
Thanks for reading, and please let me know if you have any questions!
感谢您的阅读,如果您有任何疑问,请告诉我!