[Numpy-discussion] re carray and datetime objects

John [H2O] washakie@gmail....
Mon Jul 20 06:48:25 CDT 2009


I have a file containing mixed data types: strings, floats, datetime
output(i.e. strings), and ints. Something like:

#ID, name, date, value
1,sample,2008-07-10 12:34:20,344.56

And so forth. It seems using recarrays is efficient and a prefered habit to
get into wrg to numpy, so I am trying the following:


DATA = np.loadtxt(infile,dtype=dtype)

This works if I set 'date' type to 'S20', but wouldn't it be more
appropriate to use object? Also, what is the next step to then use the
values as datetime objects?

Do I have to take the data out of the array, convert to datetime, then put
back in the array?

dates = DATA['date']
dates = [dt.datetime.strptime(d,'%Y-%m-%d %H:%M:%S') for d in dates]
DATA['dates'] = np.array(dates)


View this message in context: http://www.nabble.com/recarray-and-datetime-objects-tp24568340p24568340.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.

More information about the NumPy-Discussion mailing list