How to convert from pandas.DatetimeIndex to numpy.datetime64?
I get:
>>> type(df.index.to_datetime())
Out[56]: pandas.tseries.index.DatetimeIndex
Is it safe to do numpy.array(datetimeindex,dtype=numpy.datetime64)?
The data inside is of datetime64 dtype (datetime64[ns] to be precise). Just take the values attribute of the index. Note it will be nanosecond unit.
pd.date_range("20120101", "20120102").values yields array([1970-01-16 224:00:00, 1970-01-16 248:00:00], dtype=datetime64[ns]), which is not correct.