[Answered ]-How to convert from MySQL datetime to numpy datetime64?

2👍

You can use explicit unit specification in datetime data type:

import datetime

row = ['resource', 1, 1.1, datetime.now(), 10]
r_rows = [row]

data_type = [('resource_name', np.str, 100),
             ('mobile_id_id', np.int8),
             ('value', np.float),
             ('update_time', '<M8[us]'),
             ('capacity', np.int8)]

narray = np.fromiter((tuple(row) for row in r_rows), dtype=data_type)

results in

>>> narray['update_time'][0]
numpy.datetime64('2013-12-03T16:27:05.456766+0000')
👤alko

Leave a comment