1、numpy
1)numpy.log:以10为底:
>>> import numpy as np
>>> np.log10(x)
结果如下:
>>> np.log10(100)
2.0
2)numpy.log:e为底
log下什么都不写默认是自然对数
如:
>>> np.log(np.e)
1.0
>>> np.log(10)
2.3025850929940459
numpy.unique()保留数组中不同的值,返回两个参数。
>>> import numpy as np
>>> a=np.random.randint(0,5,8)
>>> a
array([4, 2, 4, 0, 0, 1, 0, 4])
>>> np.unique(a)
array([0, 1, 2, 4])
4)zeros,生成全部为0的数组
2、pandas
1)pd.dropna根据各标签的值中是否存在缺失数据,对轴标签进行过滤
2)pd.diff计算差集,产生一个新的Index
常用函数手册
pandas在线文档
3)DataFrame 数据合并,连接(merge,join,concat)
3、zip函数
使用zip()函数来可以把列表合并,并创建一个元组对的列表。
>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> z = [7, 8, 9]
>>> xyz = zip(x, y, z)
>>> print xyz
结果为:
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
实际输出如下:
>>> zip(x,y,z)
如果要显示出结果,必须用list函数
>>> list(zip(x,y,z))
zip()参数可以接受任何类型的序列,同时也可以有两个以上的参数;当传入参数的长度不同时,zip能自动以最短序列长度为准进行截取,获得元组.
>>> l1,l2,l3 = (1,2,3),(4,5,6),(7,8,9)
>>> list(zip(l1,l2,l3))
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
>>> str1 = 'abc'
>>> str2 = 'def123'
>>> zip(str1,str2)
[('a', 'd'), ('b', 'e'), ('c', 'f')]
搭配for循环,支持并行迭代操作方法:
l1 = [2,3,4]
l2 = [4,5,6]
for (x,y) in zip(l1,l2):
(print x,y,'--',x*y)
2 4 -- 8
3 5 -- 15
4 6 -- 24