Numpy structured array with datetime
numpy, python
Solution
You have to specify that the `datetime64` is in seconds when you create the array because the one you parse and try to assign is a `datetime64[s]`:
na_trades = np.zeros(2, dtype='datetime64[s],i4')
na_trades[0] = (np.datetime64('1971-01-01 00:00:00'), 0)
The error you get means that the `datetime64` object that you specified is not `same_kind` as the one you try to assing. You try to assign a seconds resolution one, and you created a different one when you constructed the array (by default I think it's nanoseconds).
Problem
I tried to build a structured array with a datetime coloumn ``` import numpy as np na_trades = np.zeros(2, dtype = 'datetime64,i4') na_trades[0] = (np.datetime64('1970-01-01 00:00:00'),0) TypeError: Cannot cast NumPy timedelta64 scalar from metadata [s] to according to the rule 'same_kind' ``` Is there a way to fix this?