Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何从 转换pandas.DatetimeIndex为numpy.datetime64?
pandas.DatetimeIndex
numpy.datetime64
我得到:
>>> type(df.index.to_datetime()) Out[56]: pandas.tseries.index.DatetimeIndex
这样做安全numpy.array(datetimeindex,dtype=numpy.datetime64)吗?
numpy.array(datetimeindex,dtype=numpy.datetime64)
里面的数据是datetime64dtype (datetime64[ns]准确地说)。只需获取values索引的属性。请注意,它将是纳秒单位。
datetime64
datetime64[ns]
values
我会这样做:-
new_array = np.array(df.index.to_pydatetime(), dtype=numpy.datetime64)
使用to_pydatetime()方法。
to_pydatetime()