数据分析

1-IPython的使用

2018-10-13  本文已影响0人  撸撸很乖张

Ipyhon快捷键

markdown 中可以使用html语法 <font color='red' size=5>abc</font>

帮助文档

help(函数)

函数?

函数? 自己写的函数显示源码

Ipyhon魔法指令

运行外部python文件

%run *.py  # 当前路径

%run '/home/dai/Desktop/test.py'  

当我们使用魔法命令执行了一个外部文件时,该文件的函数就能在当前会话中使用

运行计时

用下面命令计算statement的平均运行时间:   
> %timeit statement

timeit会多次运行statement,最后得到一个更为精准的预期运行时间


可以使用两个百分号来测试多行代码的平均运行时间:

`
%%timeit

statement1

statement2

statement3

`

记住:
- %time一般用于耗时长的代码段
- %timeit一般用于耗时短的代码段

快速查看当前会话的所有变量与函数名称:

%who

查看当前会话的所有变量与函数名称的详细信息:

%whos

返回一个字符串列表,里面元素是当前会话的所有变量与函数名称:

%who_ls

执行linux指令

Linux指令:

$ echo "hello world" # echo is like Python's print function hello world

$ pwd # pwd = print working directory /home/jake # this is the "path" that we're sitting in

$ ls # ls = list working directory contents notebooks projects

$ mkdir mm /home/jake/projects

$touch txt !touch /home/nanfengpo/Desktop/xx/hello.txt

在Linux指令之前加上 !,即可在ipython当中执行Linux指令。

注意会将标准输出以字符串形式返回

更多魔法指令

lsmagic

上一篇 下一篇

猜你喜欢

热点阅读