我想用 Python 对 csv 文件中的每一行进行计算。这是 loaddataa 文件:import osimport pandas as pddef loadData(relativPath): files = os.listdir(relativPath) path = os.path.abspath(relativPath) datas = list() for file in files: absPath = path + "/" + file print(absPath) data = pd.read_csv(absPath) datas.append(data) return datas这些是我的第一步:import math as mimport loaddataa as ld dataListStride = ld.loadData("../Data/Fabienne") indexStrideData = 1 strideData = dataListStride[indexStrideData]def horizontal(yAngle, yAcceleration, xAcceleration): a = (m.cos(yAngle)*yAcceleration)-(m.sin(yAngle)*xAcceleration) return aresultsHorizontal = list()for i in range (len(strideData)): strideData_yAngle = strideData.to_numpy()[i, 2] strideData_xAcceleration = strideData.to_numpy()[i, 4] strideData_yAcceleration = strideData.to_numpy()[i, 5] ...... ......在 for - 循环中我不知道如何继续下去。csv - 文件由 9 列和 150 行组成。对于计算,我只需要第 2、4 和 5 列。使用中的公式进行的计算def horizontal应在每一行上执行,因此最后我有 150 个值。我希望很清楚我想做什么。谢谢你帮助我。
1 回答
慕婉清6462132
TA贡献1804条经验 获得超2个赞
在每个循环中调用该horizontal()函数,并使用 将结果添加到您的列表中resultsHorizontal.append()。
代码:
resultsHorizontal = list()
for i in range (len(strideData)):
strideData_yAngle = strideData.to_numpy()[i, 2]
strideData_xAcceleration = strideData.to_numpy()[i, 4]
strideData_yAcceleration = strideData.to_numpy()[i, 5]
resultsHorizontal.append(horizontal(strideData_yAngle, strideData_yAcceleration, strideData_xAcceleration))
添加回答
举报
0/150
提交
取消