一、Jupyter Notebook 已迅速成为数据分析,机器学习的必备工具。因为它可以让数据分析师集中精力向用户解释整个分析过程。

Jupyter notebook(http://jupyter.org/) 是一种 Web 应用,能让用户将说明文本、数学方程、代码和可视化内容全部组合到一个易于共享的文档中。

  • 名字源自Julia、Python 和 R(数据科学的三种开源语言)
  • 是一款程序员和科学工作者的编程/文档/笔记/展示软件
  • .ipynb文件格式是用于计算型叙述的JSON文档格式的正式规范

二、启动 Jupyter Notebook

    首先安装 Jupyter 的最简单方法是使用 Anaconda。该发行版附带了 Jupyter notebook。你能够在默认环境下使用 notebook。确保你已经安装了Anaconda。

动手深度学习jupyter notebook jupyter notebook简介_ide

 

Anaconda https://www.anaconda.com/products/individual 或直接到官网下载

动手深度学习jupyter notebook jupyter notebook简介_命令模式_02

它也是一款集成软件,因为能看到过程运行结果,做数据分析比pycharm更友好。希望与原来的独立,可选择安装。

 三、快速上手notebook

 1、直接单击

动手深度学习jupyter notebook jupyter notebook简介_命令模式_03

自动启动页面

动手深度学习jupyter notebook jupyter notebook简介_命令模式_04

 

 

2.新建notebook文档

  • notebook的文档格式是.ipynb

动手深度学习jupyter notebook jupyter notebook简介_ide_05

 

 3.内容界面操作

   标题栏:点击标题(如Untitled)修改文档名(左上角)

动手深度学习jupyter notebook jupyter notebook简介_jupyter_06

 可以修改名

动手深度学习jupyter notebook jupyter notebook简介_python_07

4. cell操作

cell:一对In Out会话被视作一个代码单元,称为cell

动手深度学习jupyter notebook jupyter notebook简介_ide_08


cell行号前的 * ,表示代码正在运行

 

动手深度学习jupyter notebook jupyter notebook简介_ide_09


Jupyter支持两种模式:

编辑模式(Enter)
    命令模式下回车Enter或鼠标双击cell进入编辑模式
    可以操作cell内文本或代码,剪切/复制/粘贴移动等操作
命令模式(Esc)
    按Esc退出编辑,进入命令模式
     可以操作cell单元本身进行剪切/复制/粘贴/移动等操作

5. 鼠标操作

动手深度学习jupyter notebook jupyter notebook简介_命令模式_10

6.关闭notebook文件 

动手深度学习jupyter notebook jupyter notebook简介_python_11

 

 7、上传notebook文件

    

动手深度学习jupyter notebook jupyter notebook简介_命令模式_12

 8、共享你的notebook

单击File->Download as,你可以选择多种格式下载你的notebook。一般我都会根据下面的用途来选择不同的下载格式:

1)如果我想和客户分享我的数据分析成果,我会选择将notebook下载为HTML文件。

2)如果我希望将自己的数据分析成果和代码嵌入到项目中,比如为药店管理系统做个数据分析子模块,我就会选择Python(.py)模块,这可以将我的代码融入项目中,成为子模块,方便和其他开发人员共同完成任务。

3)如果要在博客或文档中使用 notebook,我就选择Markdown格式。

4)默认的notebook文件后缀是.ipynb

动手深度学习jupyter notebook jupyter notebook简介_数据分析_13

9、 关闭Jupler notebook服务器

直接关闭打开notebook的页面就可以。再次提醒,这会立即关闭所有运行中的 notebook,因此,请确保你保存了工作!

关闭notebook服务器后,下次启动再打开notebook,当你继续在该notebook中写代码时,发现之前的变量无法访问了。需要你在该notebook的Kernerl选项卡中选择“Run All”重新编译下之前的代码。

动手深度学习jupyter notebook jupyter notebook简介_ide_14

10、 快捷键操作
   两种模式通用快捷键

   Shift+Enter,执行本单元代码,并跳转到下一单元
   Ctrl+Enter,执行本单元代码,留在本单元
命令模式:按ESC进入

Y,cell切换到Code模式

M,cell切换到Markdown模式

A,在当前cell的上面添加cell

B,在当前cell的下面添加cell

其他(了解)

双击D:删除当前cell

Z,回退

L,为当前cell加上行号 <!–

Ctrl+Shift+P,对话框输入命令直接运行

快速跳转到首个cell,Crtl+Home

快速跳转到最后一个cell,Crtl+End -->

编辑模式:按Enter进入

补全代码:变量、方法后跟Tab键

为一行或多行代码添加/取消注释:Ctrl+/(Mac:CMD+/)

其他(了解):

多光标操作:Ctrl键点击鼠标(Mac:CMD+点击鼠标)
回退:Ctrl+Z(Mac:CMD+Z)
重做:Ctrl+Y(Mac:CMD+Y)

四、 Jupyter Notebook中自动补全代码相关功能

安装:

pip install jupyter_contrib_nbextensions

运行

jupyter contrib nbextension install --user --skip-running-check 

打开你的jupyter notebook,你就会发现,菜单栏上面多了一栏Nbextension,在那里面勾选你想要的扩展功能即可。

动手深度学习jupyter notebook jupyter notebook简介_python_15

 选择如下:

动手深度学习jupyter notebook jupyter notebook简介_jupyter_16

 效果:

动手深度学习jupyter notebook jupyter notebook简介_jupyter_17