Reputation: 9054
from numpy import genfromtxt
dataPoints = genfromtxt(temp.csv, dtype='datetime64[D],i8',delimiter=' ')
CSV File: temp.csv
2014-05-19 10
2014-05-20 11
2014-05-21 12
Output from print(dataPoints)
[ nan 10.]
[ nan 11.]
[ nan 12.]
Edit
[1969-12-31 00:00:00 1970-01-11 00:00:00]
[1969-12-31 00:00:00 1970-01-12 00:00:00]
[1969-12-31 00:00:00 1970-01-13 00:00:00]
[1969-12-31 00:00:00 1970-01-14 00:00:00]
[1969-12-31 00:00:00 1970-01-13 00:00:00]
Upvotes: 0
Views: 267
Reputation: 9172
Just tell NumPy what types to expect. E.g.:
>>> genfromtxt('temp.csv', dtype='datetime64[D],i8')
array([(datetime.date(2014, 5, 19), 10L),
(datetime.date(2014, 5, 20), 11L), (datetime.date(2014, 5, 21), 12L)],
dtype=[('f0', '<M8[D]'), ('f1', '<i8')])
Upvotes: 4