1.进入ipython:

C:\Users\Administrator>ipython
Python 3.6. (v3.6.0:41df79263a11, Dec , ::) [MSC v. bit (AM
D64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1. -- An enhanced Interactive Python. Type '?' for help.

2.常用命令:

In []: a = [,,,,]

In []: a.append() #可以用TAB键自动补全

In []: a
Out[]: [, , , , , ] In []: a? #加一个?查看a的详细信息
Type: list
String form: [, , , , , ]
Length:
Docstring:
list() -> new empty list
list(iterable) -> new list initialized from iterable's items In []: def func(a,b):
...: """docstring test"""
...: return a+b
...: In []: func?? #加两个?查看函数的详细信息
Signature: func(a, b)
Source:
def func(a,b):
"""docstring test"""
return a+b
File: c:\users\administrator\<ipython-input--64258f09b59c>
Type: function

In [8]: a.a*?
 a.append

In [7]: a
 Out[7]: [1, 2, 3, 4, 5, 2]

In [9]: a.*?  #查看列表a的常用方法

a.__add__
 a.__class__
 a.__contains__
 a.__delattr__
 a.__delitem__
 a.__dir__
 a.__doc__
 a.__eq__
 a.__format__
 a.__ge__
 a.__getattribute__
 a.__getitem__
 a.__gt__
 a.__hash__
 a.__iadd__
 a.__imul__
 a.__init__
 a.__init_subclass__
 a.__iter__
 a.__le__
 a.__len__
 a.__lt__
 a.__mul__
 a.__ne__
 a.__new__
 a.__reduce__
 a.__reduce_ex__
 a.__repr__
 a.__reversed__
 a.__rmul__
 a.__setattr__
 a.__setitem__
 a.__sizeof__
 a.__str__
 a.__subclasshook__
 a.append
 a.clear
 a.copy
 a.count
 a.extend
 a.index
 a.insert
 a.pop
 a.remove
 a.reverse
 a.sort

命令:

In [11]: a.__*__?
a.__add__
a.__class__
a.__contains__
a.__delattr__
a.__delitem__
a.__dir__
a.__doc__
a.__eq__
a.__format__
a.__ge__
a.__getattribute__
a.__getitem__
a.__gt__
a.__hash__
a.__iadd__
a.__imul__
a.__init__
a.__init_subclass__
a.__iter__
a.__le__
a.__len__
a.__lt__
a.__mul__
a.__ne__

In [12]: def func(a,b):
...: """docstring test"""
...: return a/b
...: a = 10
...: b = 2
...: c = func(a,b)
...: print(c)
...:
5.0

可以拖动文件夹至ipython界面进入指定目录

In [24]: cd D:\projects
D:\projects

In [25]: %run test.py
5.0  #输出

In [28]: !ipconfig  #加感叹号运行命令

Windows IP 配置

无线局域网适配器 无线网络连接 8:

连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::f076:cf21:6241:d7f%25
IPv4 地址 . . . . . . . . . . . . : 192.168.191.1
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . :

python求函数运行时间一般要用到装饰器,但是ipython的方法是:多次运行函数并求平均(%timeit func(1,2))

In [29]: %timeit func(1,2)
134 ns ± 4.55 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each

更改函数信息:

>>> def func(a,b):
... return a/b

func(10,0)

python3报错信息

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in func
ZeroDivisionError: division by zero

In [30]: #%paste

In [30]: def func(a,b):
...: """docstring test"""
...: return a/b
...: a = 10
...: b = 0
...: c = func(a,b)
...: print(c)
...:
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-30-301f9b654341> in <module>()
4 a = 10
5 b = 0
----> 6 c = func(a,b)
7 print(c)

<ipython-input-30-301f9b654341> in func(a, b)
1 def func(a,b):
2 """docstring test"""
----> 3 return a/b  #用箭头指向错误的行
4 a = 10
5 b = 0

ZeroDivisionError: division by zero

抛出异常

In [31]: %pdb on
Automatic pdb calling has been turned ON #启动调试器

In [32]: %paste #粘贴要复制的内容
def func(a,b):
"""docstring test"""
return a/b
a = 10
b = 0
c = func(a,b)
print(c)

## -- End pasted text --
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-32-6cfa0b0f11a2> in <module>()
4 a = 10
5 b = 0
----> 6 c = func(a,b)
7 print(c)

<ipython-input-32-6cfa0b0f11a2> in func(a, b)
1 def func(a,b):
2 """docstring test"""
----> 3 return a/b
4 a = 10
5 b = 0

ZeroDivisionError: division by zero
> <ipython-input-32-6cfa0b0f11a2>(3)func()
1 def func(a,b):
2 """docstring test"""
----> 3 return a/b #设置了断点
4 a = 10
5 b = 0

ipdb> p a
10
ipdb> p b
0
ipdb> q#退出调试

In [33]:

a.用上下键可以查看历史命令

In [33]: a = 1

In [34]: b =2

In [35]: c = a+b

In [36]: a+b
Out[36]: 3

In [37]: _ #查看上一条命令的结果
Out[37]: 3

In [39]: a*b
Out[39]: 2

In [40]: a+b
Out[40]: 3

In [41]: __ #查看上两条命令的结果
Out[41]: 2

可以查看上第三条,第四条就不行了

In [42]: ___
Out[42]: 2

In [43]: ____
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-43-a09794d69507> in <module>()
----> 1 ____

NameError: name '____' is not defined
> <ipython-input-43-a09794d69507>(1)<module>()
----> 1 ____

3.jupyter notebook

pip3 install jupyter 

新建:

pycharm新建jupyter notebook

4.numpy基本使用

4.1

In [44]: import numpy as np

In [45]: np.array([1,2,3,4,5])
Out[45]: array([1, 2, 3, 4, 5])

In [46]: for i in _: #for循环上一个数组
...: print(i)
...:
1
2
3
4
5

In [47]: a = list(range(100))

In [48]: a
Out[48]:

[0,1,2,3,...,99,100]

查看a占用的内存:

In [50]: import sys

In [51]: sys.getsizeof(a)
Out[51]: 1008 字节

In [52]: b = np.array(range(100))

In [53]: b
Out[53]:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99])

In [54]: sys.getsizeof(b)
Out[54]: 496

In [56]: import random as rd

In [57]: prize = [random.uniform(10.0,20.0) for i in range(20)]

In [58]: prize
Out[58]:
[10.004054627786882,
18.096649929234854,
14.43396704748472,
12.20024053360273,
17.176704067418257,
13.007875001992808,
19.97226551920407,
15.510685953676614,
11.584123618476683,
11.069274429538424,
10.266891497698419,
13.762984583010937,
17.668216765172286,
10.01516244592815,
11.443377100041701,
13.034463476325001,
13.680557780172048,
19.745559061062647,
14.12108494581293,
15.738287202323185]

In [59]: prize = [round(random.uniform(10.0,20.0),2) for i in range(20)]#取两位小数

In [60]: prize
Out[60]:
[16.44,
17.95,
16.07,
19.17,
18.02,
13.22,
13.17,
14.59,
14.29,
19.66,
11.19,
14.29,
12.59,
17.82,
18.38,
10.65,
14.67,
17.92,
11.78,
15.96]

In [12]: import random

In [13]: import random as rd

In [6]: num = [random.randint(1,10) for i in range(20)]

In [7]: num
Out[7]: [7, 9, 8, 4, 7, 8, 9, 6, 6, 4, 8, 10, 1, 6, 4, 10, 5, 8, 1, 5]

In [14]: prize = [random.uniform(10.0,20.0) for i in range(20)]

In [16]: prize = [round(random.uniform(10.0,20.0),2) for i in range(20)]

In [20]: sum = 0

In [21]: for i,j in zip(prize,num):
...: sum+=i*j
...:

In [22]: sum
Out[22]: 1899.42

def func(a,b):
sum = 0
for i,j in zip(a,b):
sum+=i*j
return sum

In [25]: %timeit func(prize,num) #运行时间
2.28 µs ± 81.2 ns per loop (mean ± std. dev. of 7 runs, 100000 loops eac

In [25]: %timeit func(prize,num)
2.28 µs ± 81.2 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

#计算商品总价,方法1

In [26]: prize_np = np.array(prize)

In [27]: num_np = np.array(num)

In [28]: np.dot(prize_np,num_np)算出商品总价#向量的点乘
Out[28]: 1899.4200000000001

In [29]: %timeit np.dot(prize_np,num_np)#查看运行的时间
1.3 µs ± 13.4 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

#计算商品总价,方法2

In [30]: prize_np * num_np
Out[30]:
array([ 91.36, 171. , 11.19, 111.84, 37.42, 133.29, 86.96,
31.72, 37.72, 33.39, 142.88, 41.16, 123.44, 141.84,
46.08, 113.22, 163.8 , 100.92, 130.27, 149.92])

In [31]: _.sum()#求和
Out[31]: 1899.4200000000001

In [24]: prize_np.dtype#数据类型
Out[24]: dtype('float64')#64位长度,占8字节

In [27]: a = np.arange(1000)

In [28]: a.size
Out[28]: 1000

In [29]: a.shape
Out[29]: (1000,)

In [30]: a = np.arange(1000)

In [31]: z = np.array([[1,2,3],[4,5,6]])

In [32]: z
Out[32]:
array([[1, 2, 3],
[4, 5, 6]])

In [33]: z.size #大小
Out[33]: 6

In [34]: z.shape #形状
Out[34]: (2, 3)#矩阵两行三列

In [35]: z.ndim#维度
Out[35]: 2  #二维数组

In [36]: a.ndim
Out[36]: 1  #一维数组

In [37]: z.T #行变成列,列变成行 (转制)
Out[37]:
array([[1, 4],
      [2, 5],
      [3, 6]])

In [38]: z.dtype
Out[38]: dtype('int32')

In [39]: z
Out[39]:
array([[1, 2, 3],
[4, 5, 6]])

In [40]: z[0][0]=3.2

In [41]: z
Out[41]:
array([[3, 2, 3],
[4, 5, 6]])

In [42]: z
Out[42]:
array([[3, 2, 3],
[4, 5, 6]])

In [43]: z.dtype = 'float32'

In [44]: z
Out[44]:
array([[ 4.20389539e-45, 2.80259693e-45, 4.20389539e-45],
[ 5.60519386e-45, 7.00649232e-45, 8.40779079e-45]], dtype=float32)

In [45]: z.dtype = 'int32'

In [46]: z
Out[46]:
array([[3, 2, 3],
[4, 5, 6]])

In [47]: z.astype('float32')
Out[47]:
array([[ 3., 2., 3.],
[ 4., 5., 6.]], dtype=float32)

In [48]: z
Out[48]:
array([[3, 2, 3],
[4, 5, 6]])

In [49]: z = z.astype('float32')

In [50]: z
Out[50]:
array([[ 3., 2., 3.], #.代表是*.0
      [ 4., 5., 6.]], dtype=float32)

In [56]: z = z.astype('float32')

In [57]: z
Out[57]:
array([[ 1., 2., 3.],
[ 4., 5., 6.]], dtype=float32)

In [58]: z[0][0]=3.2

In [59]: z
Out[59]:
array([[ 3.20000005, 2. , 3. ],
[ 4. , 5. , 6. ]], dtype=float32)

python金融分析项目的更多相关文章

  1. Pycharm+django新建Python Web项目

    这两天初学Python,首先是学习Python语法有PyCharm就可以运行Console程序了,因为是初学所以,尽量写的比较详细,包括参考的资料地址...   1.下载Python,并安装[本文版本 ...

  2. Python(Django)项目与Apache的管理

    (开开心心每一天~ ---虫瘾师) Python(Django)项目交给Apache的管理(一) 准备:Django的环境(Python).Apache.Wsgi(必须文件) 首先需要电脑有Pytho ...

  3. Python(Django)项目与Apache的管理交互

    (开开心心每一天~ ---虫瘾师) Python(Django)项目交给Apache的管理(一) 准备:Django的环境(Python).Apache.Wsgi(必须文件) 首先需要电脑有Pytho ...

  4. 再一波Python实战项目列表

    前言: 近几年Python可谓是大热啊,很多人都纷纷投入Python的学习中,以前我们实验楼总结过多篇Python实战项目列表,不但有用还有趣,最主要的是咱们实验楼不但有详细的开发教程,更有在线开发环 ...

  5. 使用Nginx+Uwsgi部署Python Flask项目

    第一次用Flask做Web(也是第一次用Python做Web),在部署的时候遇到了不少问题,现在将过程就下来,供在这方面也有疑惑的人参考.(PS:使用Apache+mod_wsgi部署模式的可以参考另 ...

  6. 机器学习 Top 20 Python 开源项目

    转自:http://mp.weixin.qq.com/s?__biz=MzA4MjEyNTA5Mw==&mid=2652565022&idx=1&sn=9aa035097120 ...

  7. python实战===2017年30个惊艳的Python开源项目 (转)

    本文转自:http://www.sohu.com/a/216723120_115128 摘要:本文来自Mybridge,介绍了过去一年里30个惊艳的Python开源项目.点击每一个都可以在GitHub ...

  8. 10大Python开源项目推荐(Github平均star2135)

    翻译 | suisui 来源 | 人工智能头条(AI_Thinker) 继续假日充电系列~本文是 Mybridge 挑选的 10 个 Python 开源项目,Github 平均star 2135,希望 ...

  9. 32个Python爬虫项目让你一次吃到撑

    整理了32个Python爬虫项目.整理的原因是,爬虫入门简单快速,也非常适合新入门的小伙伴培养信心.所有链接指向GitHub,祝大家玩的愉快~O(∩_∩)O WechatSogou [1]- 微信公众 ...

随机推荐

  1. 如何高效的遍历HashMap 以及对key 进行排序

    Map<Integer ,Object> map = new HashMap<Integer,Object>(); for(int i = 0; i<=100;i++){ ...

  2. Spring AOP (事务管理)

    一.声明式事务管理的概括 声明式事务(declarative transaction management)是Spring提供的对程序事务管理的方式之一. Spring的声明式事务顾名思义就是采用声明 ...

  3. app安全研究

    国内Android App在线漏洞检测平台  腾讯金刚审计系统 http://service.security.tencent.com/kingkong 免费 无限制 腾讯御安全 http://yaq ...

  4. CentOS系统下yum命令的详细使用方法

    yum是什么yum = Yellow dog Updater, Modified 主要功能是更方便的添加/删除/更新RPM包. 它能自动解决包的倚赖性问题. 它能便于管理大量系统的更新问题 yum特点 ...

  5. Python3.x:代理ip刷点赞

    Python3.x:代理ip刷点赞 声明:仅供为学习材料,不允许用作商业用途: 一,功能: 针对某网站对企业自动刷点赞: 网站:https://best.zhaopin.com/ 二,步骤: 1,获取 ...

  6. android与linux之间的关系

    篇一(system/core/init/init.c): 对Android感兴趣的朋友都知道,Android系统是建立在Linux内核之上的.那么Linux内核和Android什么关系?Linux内核 ...

  7. webservice的cxf和spring整合客户端开发

    1.新建一个java项目 2.导入cxf相关的jar包,并部署到项目中 3.用命令生成客户端使用说明文档 wsdl2java -p com.xiaostudy -d . http://127.0.0. ...

  8. js 弹出层,以及在javascript里定义层样式

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. [转载]Eclipse的常用快捷键

    常用的快捷键 ctrl+1:快速修复错误 ctrl+shift+L :查看快捷键 alt+?或alt+/:自动补全代码或者提示代码 ctrl+o:快速outline视图 ctrl+shift+r:打开 ...

  10. 【Python】常用排序算法的python实现和性能分析

    作者:waterxi 原文链接 背景 一年一度的换工作高峰又到了,HR大概每天都塞几份简历过来,基本上一天安排两个面试的话,当天就只能加班干活了.趁着面试别人的机会,自己也把一些基础算法和一些面试题整 ...