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)
這一切確實是輸出中的源文件的轉置。看來我無法將列表中的單個條目本身變成列表。我在這裏做錯了什麼?任何幫助,建議和指導,非常感謝。