zip 在数据分析中的用法
#在python console 里面进行测试
a=[1,2,3,4,5,6] b=[0.13,0.78,0.6,0.92,0.66,0.33] zip(a,b) Out[4]: <zip at 0x10f938308> for i in zip(a,b): print(i) (1, 0.13) (2, 0.78) (3, 0.6) (4, 0.92) (5, 0.66) (6, 0.33)
for i in range(6): a_i=a[i] b_i=b[i] print(a_i,b_i) 1 0.13 2 0.78 3 0.6 4 0.92 5 0.66 6 0.33
[i for i in zip(a,b)] Out[9]: [(1, 0.13), (2, 0.78), (3, 0.6), (4, 0.92), (5, 0.66), (6, 0.33)]
#转数组 import numpy as np a_array=np.array(a) b_array=np.array(b) result=a_array*b_array result Out[14]: array([0.13, 1.56, 1.8 , 3.68, 3.3 , 1.98]) result.max() Out[15]: 3.68 result.min() Out[16]: 0.13 result.sum() Out[17]: 12.450000000000001 result.argmax() Out[18]: 3