精心整理的jupyter notebook基本使用方法,分享给大家。
感谢大家的点赞与关注,欢迎共同学习交流。

jupyter中ipython的基本使用方法

  • 一、启动程序
  • 二、IPython的帮助文档
    • 1、使用help()
    • 2、使用"?"
    • 3、使用"tab"键自动补全
  • 三、IPython魔法命令
    • 1、运行在外部Python文件
    • 2、查看运行计时
    • 3、查看当前会话中所有的变量与函数
    • 4、执行系统终端指令
    • 5、更多魔法指令或者cmd
  • 四、快捷键
    • 1、命令模式
    • 2、编辑模式

一、启动程序

命令:jupyter notebook

这个命令可以启动jupyter的交互服务器,并且把当前目录作为映射打开一个web界面,加载映射的目录结构

【注意】如果这个命令提示错误,检测环境变量还有anaconda是否安装完全(如果不完全:手动安装pip install jupyter)

二、IPython的帮助文档

1、使用help()

help(list)
Help on class list in module builtins:class list(object)|  list() -> new empty list|  list(iterable) -> new list initialized from iterable's items|  |  Methods defined here:|  |  __add__(self, value, /)|      Return self+value.|  |  __contains__(self, key, /)|      Return key in self.|  |  __delitem__(self, key, /)|      Delete self[key].|  |  __eq__(self, value, /)|      Return self==value.|  |  __ge__(self, value, /)|      Return self>=value.|  |  __getattribute__(self, name, /)|      Return getattr(self, name).|  |  __getitem__(...)|      x.__getitem__(y) <==> x[y]|  |  __gt__(self, value, /)|      Return self>value.|  |  __iadd__(self, value, /)|      Implement self+=value.|  |  __imul__(self, value, /)|      Implement self*=value.|  |  __init__(self, /, *args, **kwargs)|      Initialize self.  See help(type(self)) for accurate signature.|  |  __iter__(self, /)|      Implement iter(self).|  |  __le__(self, value, /)|      Return self<=value.|  |  __len__(self, /)|      Return len(self).|  |  __lt__(self, value, /)|      Return self<value.|  |  __mul__(self, value, /)|      Return self*value.n|  |  __ne__(self, value, /)|      Return self!=value.|  |  __new__(*args, **kwargs) from builtins.type|      Create and return a new object.  See help(type) for accurate signature.|  |  __repr__(self, /)|      Return repr(self).|  |  __reversed__(...)|      L.__reversed__() -- return a reverse iterator over the list|  |  __rmul__(self, value, /)|      Return self*value.|  |  __setitem__(self, key, value, /)|      Set self[key] to value.|  |  __sizeof__(...)|      L.__sizeof__() -- size of L in memory, in bytes|  |  append(...)|      L.append(object) -> None -- append object to end|  |  clear(...)|      L.clear() -> None -- remove all items from L|  |  copy(...)|      L.copy() -> list -- a shallow copy of L|  |  count(...)|      L.count(value) -> integer -- return number of occurrences of value|  |  extend(...)|      L.extend(iterable) -> None -- extend list by appending elements from the iterable|  |  index(...)|      L.index(value, [start, [stop]]) -> integer -- return first index of value.|      Raises ValueError if the value is not present.|  |  insert(...)|      L.insert(index, object) -- insert object before index|  |  pop(...)|      L.pop([index]) -> item -- remove and return item at index (default last).|      Raises IndexError if list is empty or index is out of range.|  |  remove(...)|      L.remove(value) -> None -- remove first occurrence of value.|      Raises ValueError if the value is not present.|  |  reverse(...)|      L.reverse() -- reverse *IN PLACE*|  |  sort(...)|      L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE*|  |  ----------------------------------------------------------------------|  Data and other attributes defined here:|  |  __hash__ = None
help(len)
Help on built-in function len in module builtins:len(obj, /)Return the number of items in a container.
len("123")
3

2、使用"?"

len?
list?

“?”调出一个函数的帮助文档,“??”调出一个函数的帮助文档以及源码

len??
def add_sum(a,b):"求两个数的和"c = a+breturn c
add_sum??

3、使用"tab"键自动补全

aaaaa=10
import numpyaaaaa
10

三、IPython魔法命令

1、运行在外部Python文件

%run xx.py
下面例子中的外部test.py文件的内容如下:

def hello(a):c = a**2m = 10000return c
w = 10000

以下为在Jupyter notebook中输入的代码:

%run test.py
hello(10)
100
w
10000
m # m是局部变量
---------------------------------------------------------------------------NameError                                 Traceback (most recent call last)<ipython-input-24-69b64623f86d> in <module>()
----> 1 mNameError: name 'm' is not defined

2、查看运行计时

%time print("hello")
hello
Wall time: 0 ns
def func1():res = 0for i in range(1000):res += 1for j in range(1000):res -= 1
%time func1()
Wall time: 65.5 ms
%timeit func1()
76.8 ms ± 4.24 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
%%timeit
print("afda")
func1()
list("123")
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
afda
136 ms ± 19.3 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

%time 一般耗时比较多的代码用这个
%timeit 一般是耗时比较少的代码

3、查看当前会话中所有的变量与函数

%who
a     aaaaa   add_sum     func1   hello   numpy   w
%whos
Variable   Type        Data/Info
--------------------------------
a          int         10
aaaaa      int         10
add_sum    function    <function add_sum at 0x000001957CA21840>
func1      function    <function func1 at 0x000001957CEEB840>
hello      function    <function hello at 0x000001957CEEB8C8>
numpy      module      <module 'numpy' from 'C:\<...>ges\\numpy\\__init__.py'>
w          int         10000
%who_ls
['a', 'aaaaa', 'add_sum', 'func1', 'hello', 'numpy', 'w']

%who、%whos、%who_ls查看当前cell运行的时候,ipython服务器中有那些函数和变量以及框架库(modele)等存在

4、执行系统终端指令

写法:!指令名(在windows系统下应该执行Windows的系统命令,linux要执行对应的Linux版本的系统zhil)

!ipconfig
Windows IP 配置以太网适配器 以太网:连接特定的 DNS 后缀 . . . . . . . : 本地链接 IPv6 地址. . . . . . . . : fe80::b5c8:db48:5d06:3657%5IPv4 地址 . . . . . . . . . . . . : 10.31.153.97子网掩码  . . . . . . . . . . . . : 255.255.255.0默认网关. . . . . . . . . . . . . : 10.31.161.1
!cd ..
!mkdir ppp

5、更多魔法指令或者cmd

列出所有的魔法指令
%lsmagic

%lsmagic
Available line magics:
%alias  %alias_magic  %autocall  %automagic  %autosave  %bookmark  %cd  %clear  %cls  %colors  %config  %connect_info  %copy  %ddir  %debug  %dhist  %dirs  %doctest_mode  %echo  %ed  %edit  %env  %gui  %hist  %history  %killbgscripts  %ldir  %less  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %macro  %magic  %matplotlib  %mkdir  %more  %notebook  %page  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %popd  %pprint  %precision  %profile  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %qtconsole  %quickref  %recall  %rehashx  %reload_ext  %ren  %rep  %rerun  %reset  %reset_selective  %rmdir  %run  %save  %sc  %set_env  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmodeAvailable cell magics:
%%!  %%HTML  %%SVG  %%bash  %%capture  %%cmd  %%debug  %%file  %%html  %%javascript  %%js  %%latex  %%markdown  %%perl  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%script  %%sh  %%svg  %%sx  %%system  %%time  %%timeit  %%writefileAutomagic is ON, % prefix IS NOT needed for line magics.
%cd?
print("sdafads")
sdafads

四、快捷键

1、命令模式

enter: 转入编辑模式

shift+enter:运行本行,并且选中下行

ctrl+enter: 运行本行,并且选中本行

alt+enter:运行本行,并且插入一个新的cell

Y:cell转入代码状态

M:cell转入Markdown状态

A: 在上方插入一个新的cell

B:在下方插入一个新的cell

双击D:删除当前cell

2、编辑模式

tab(或shift+tab)键:提示

ctrl+a:全选当前cell

ctrl+z:撤销

jupyter中ipython的基本使用方法,帮助你更快速高效的学习相关推荐

  1. 网站分析工具使用方法的介绍,快速高效提高网站分析效率

    网站运营离不开数据分析,有分析就需要借助工具来实现,你真的会用网站分析工具吗? 目前市面上有很多不同类型的网站分析工具,有免费的和付费的,常见的工具比如GoogleAnalytics.百度统计.99c ...

  2. Java获取中文汉字拼音首字母方法一(更快速)

    实现效果 文字内容:小苹果 拼音首字母:xpg 工具类 import java.io.UnsupportedEncodingException;/*** @author yang* @version ...

  3. 在Python中操作文件之truncate()方法的使用教程

    在Python中操作文件之truncate()方法的使用教程 这篇文章主要介绍了在Python中操作文件之truncate()方法的使用教程,是Python入门学习中的基础知识,需要的朋友可以参考下 ...

  4. Javascript循环删除数组中元素的3种方法

    本文主要跟大家分享了关于Javascript循环删除数组中元素的几种方法,分享出来供大家参考学习,下面与微点阅读小编一起来看看详细的介绍: 问题 大家在码代码的过程中,经常会遇到在循环中移除指定元素的 ...

  5. jupyter中python3如何导入文件_Python·Jupyter Notebook各种使用方法

    PythonJupyter Notebook各种使用方法记录持续更新 一 Jupyter NoteBook的安装 1 新版本Anaconda自带Jupyter 2 老版本Anacodna需自己安装Ju ...

  6. Coursera | Andrew Ng (01-week-2-2.17)—Jupyter _ ipython 笔记本的快速指南

    该系列仅在原课程基础上部分知识点添加个人学习笔记,或相关推导补充等.如有错误,还请批评指教.在学习了 Andrew Ng 课程的基础上,为了更方便的查阅复习,将其整理成文字.因本人一直在学习英语,所以 ...

  7. jupyter 中重新 import 模块

    #blog [[jupyter]]是数据科学中非常常用的工具,balabalabala- 自己查去,懒得再写一遍. jupyter 中如果调用了外部的一些 py 写的模块,而好死不死,这些外部模块又需 ...

  8. Jupyter中的魔法函数

    Jupyter的魅力之处,除了体现在能提供丰富多彩的格式化文本显示,还体现在它提供了很多好用的函数.这些函数如同有魔力一般,故也被称为魔法函数(Magic Function).所谓魔法函数,实际上是I ...

  9. 在Python中连接字符串的首选方法是什么?

    本文翻译自:Which is the preferred way to concatenate a string in Python? Since Python's string can't be c ...

最新文章

  1. SAP UI5 初学者教程之六 - 了解 SAP UI5 的模块(Module)概念试读版
  2. JFreeChart(七)之气泡图表​​​​​​​
  3. 打破PermGen神话
  4. Mybatis入门---一对多、多对多
  5. iframe自适高度
  6. vue中:key 和react 中key={} 的作用,以及ref的特性?
  7. GitHub GraphQL API已正式可用
  8. 2018-2019年计算机类会议截稿日期汇总(更新至20180914)
  9. 下一代半导体表面清洁技术
  10. 如何用python实现爬虫_如何用python实现网络爬虫原理?
  11. R语言:修改chart.Correlation()函数绘制相关性图——完美出图
  12. 50本永不过时的经典计算机书籍
  13. LDA与PCA数据降维算法理论与实现(基于python)
  14. Django之自定义 form 表单上传图片
  15. Android支付接入(七):Google In-app-Billing
  16. 两个互联网公司的创业故事
  17. 为react组件增加扩展class,解决react组件不能自定义className不生效的问题
  18. 硬笔练字“州”字书写技巧,想练好都不难!
  19. python报错输出到日志_Python下的异常处理及错误日志记录
  20. jupyter notebook 杂碎

热门文章

  1. 重启Linux服务器上jar包
  2. MAC 地址(单播、组播、广播地址分类)
  3. 找不到客户采购邮箱?其实你只需要精通谷歌搜索
  4. idea如何创建c语言项目,IDEA下创建Spring项目
  5. 探索性测试的艺术(译)
  6. python正则表达式匹配汉字
  7. linux按文件大小排序
  8. 块元素,行内元素,行内块元素及相互转换
  9. 视频教程-MCSE 2012之410视频课程:安装和配置Windows Server 2012 R2-微软认证
  10. 只服程序员起名字! | 每日趣闻