python处理多行数据

from numpy import * from pandas import * price = array([4,7,10,4]) price = log(price) a= diff(price) print("a = ",a) 对于这组代码 只能处理一行的数据 但是现在我需要根据这个公式处理很多行的数据,python新手不知道怎么弄 求解答

将要处理的多组数据写成列表,然后遍历进行计算就可以了。

from numpy import * 
from pandas import *
num_list=[[4,7,10,4],[2,3,5,8],[1,5,8,3]]
for x in  num_list:
    price = array(x) 
    price = log(price) 
    a= diff(price) 
    print("a = ",a)

img

加个for循环,每次将[4,7,10,4]替换其他数据就行了