I have imported a text file into a numpy array as shown below.
data=np.genfromtxt(f,dtype=None,delimiter=',',names=None)
where f contains the path of my csv file
now data contains the following.
array([(534, 116.48482, 39.89821, '2008-02-03 00:00:49'),
(650, 116.4978, 39.98097, '2008-02-03 00:00:02'),
(675, 116.31873, 39.9374, '2008-02-03 00:00:04'),
(715, 116.70027, 40.16545, '2008-02-03 00:00:45'),
(2884, 116.67727, 39.88201, '2008-02-03 00:00:48'),
(3799, 116.29838, 40.04533, '2008-02-03 00:00:37'),
(4549, 116.48405, 39.91403, '2008-02-03 00:00:42'),
(4819, 116.42967, 39.93963, '2008-02-03 00:00:43')],
dtype=[('f0', '<i4'), ('f1', '<f8'), ('f2', '<f8'), ('f3', 'S19')])
If i now try to column slice, ie extract the first or the second column using
data[:,0]
It says "too many indices". I figured out that it is due the the way it is being stored. all the rows are being stored as tuples and not as list/array. I thought of using the "ugliest" way possible to perform slicing without having to use iteration. That would be to convert the tuples in each row to list and put it back to the numpy array. something like this
data=np.asarray([list(i) for i in data])
But for the above problem, i am losing the datatypes of each column. Each element will be stored as a string rather than integer or float which was automatically detected in the former case.
Now if i want to slice the columns without having to use iteration is there any way?