I am trying to write a script that takes csv data dumps from analog sensors, with csvs of varying lengths, and reads them into a single dimension array. The sensor samples at 32 samples/sec, so each horizontal ROW is a buffer of 32 values (1 second of data). I need all of these values, from eveny N row, in a single dimension array that I can then plot as a Y axis with matplotlib.
Here is my most recent attempt in python 2.7x. I have managed to get multiple 1D arrays, but each line is a different array, which doesn't work.
NOTE: I know how to join arrays manually, but these could be 10s, 100s, or 1000s of rows long, so I obviously need to automate this process. I am would prefer to achieve this all with the standard library and/or numpy ONLY if possible. Thanks in advance.
fo = open("data.csv", "r")
lines = fo.readlines()
for line in lines:
value = line.split(",")
result = map(float, value)
nparray = np.asarray(res)
yAxis = npa.flatten()
fo.close()
An 'example' input CSV file might look like:
1,2,3,4,5,6,7,8,9,10 \n
11,12,13,14,15,16,17,18,19,20 \n
21,22,23,24,25,26,27,28,29,30 \n
etc.. (and on and on for an UNDETERMINED amount of rows)
output:
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]
The numpy array conversion flattens the 2d array to multiple 1d arrays. The issue from there is not being able to join an unknown amount of arrays. I also realize there must be a MUCH more efficient way of doing this task in Python.