2
我从看起来像这样激光雷达传感器数据的一个csv文件,但有更bagillion行:你如何在一个列表上迭代执行一些将单个元素变为多个的操作?
scan_0,scan_1,scan_2
timestamp_0,timestamp_1,timestamp_2
7900200,7900225,7900250
logTime_0,logTime_1,logTime_2
27:46.8,27:46.8,27:46.8
distance_0,distance_0,distance_0
132,141,139
136,141,155
139,141,155
138,143,155
138,143,142
139,143,136
138,143,136
这是从一个平面的传感器数据。因此,Scan_0是时间戳特定扫描的列表或“放射状”坐标。
我的计划是:
- 阅读CSV文件导入列表
- 移调列表
打开行的每个元素到像下面的例子一个XYZ格式。
scan_0 -----> scan_0 timestamp_0-> timestamp_0 7900200-----> 7900200 logTime_0---> logTime_0 27:46.8-----> 27:46.8 distance_0--> distance_0 132---------> [132*cos(1),132*sin(1),7900200] 136---------> [136*cos(2),136*sin(2),7900200] 139---------> [139*cos(3),139*sin(3),7900200] 138---------> . . 138---------> . . 139---------> . . 138---------> [138*cos(7),139*sin(7),7900200]
每行写”
与一个坐标,最终使用的轨迹,而不是时间戳用于z从另一个csv文件的坐标XYZ坐标的数组到一个新的CSV文件。
我告诉你所有这些,所以你对我的动机有一些背景。
这里是我到目前为止有:
import csv
import numpy
from numpy import genfromtxt
from numpy import vsplit
import math
with open('2016_09_16_14_29_09_953.csv',"r") as f:
reader = csv.reader(f,delimiter = ",")
data = list(reader)
row_count = len(data)
print row_count
with open("out.csv", "a") as f1:
my_r = genfromtxt('2016_09_16_14_29_09_953.csv', delimiter=',', skip_header=6, autostrip=True) #import data
my_r = my_r.T #transpose
for x in my_r:
i=0
while i < row_count/360:
x = [x*math.cos(i), x*math.sin(i), i]
i = i + row_count/360
thedatawriter = csv.writer(f1) #setup writer
for row in my_r: #write the data
thedatawriter.writerow(row)
这一切确实是输出中的源文件的转置。看来我无法将列表中的单个条目本身变成列表。我在这里做错了什么?任何帮助,建议和指导,非常感谢。