I try to read a csv file which I need to convert into a list of floats for evaluation. The list looks like this:
[['Time [s];17063_X;17063_Y;17063_Z;17064_X;17064_Y;17064_Z;17065_X;17065_Y;17065_Z;17067_X;17067_Y;17067_Z;17068_X;17068_Y;17068_Z'], ['0;0.01952;0.04337;0.0242;0.01151;0.04152;0.03236;0.00015;-0.01679;0.05328;0.02872;0.01717;0.09341;0.01452;0.01489;0.07444'], ['0.00042;0.02188;0.04351;0.02803;0.0062;0.04108;0.03312;-0.00529;-0.01412;0.05167;0.02173;0.01377;0.04098;0.00807;0.00246;0.04354'],...]
but actually it has more than 17000 additional entries. The list I need should look like this:
[['Time [s]', '17063_X', '17063_Y', '17063_Z', '17064_X', '17064_Y', '17064_Z', '17065_X', '17065_Y', '17065_Z', '17067_X', '17067_Y', '17067_Z', '17068_X', '17068_Y', '17068_Z'], [0, 0.01952, 0.04337, 0.0242, 0.01151, 0.04152, 0.03236, 0.00015, -0.01679, 0.05328, 0.02872, 0.01717, 0.09341, 0.01452, 0.01489, 0.07444], ...]
So far I managed to get a single line (last element in list) into this format but not all the list. Here is what I've got so far:
import csv
with open(filepath, 'r') as f:
reader = csv.reader(f)
data = list(reader)
for j in range(1, len(data)): # this loop does nothing?!
for i in data[j]:
dt = i.split(';')
da = [float(i) for i in dt]
print(da)
Out:
[0.005, 0.0207, 0.02925, 0.02095, 0.02332, 0.04211, 0.02223, 0.0075, -0.01961, 0.05093, 0.02604, 0.00711, 0.06644, 0.00689, -0.00092, 0.04737]
I would appreciate any help and also some tips when it comes to list comprehension. Thanks!