12
在datetime,Timestamp和datetime64之间转换
如何将numpy.datetime64对象转换为datetime.datetime(或Timestamp)? 在下面的代码中,我创建一个datetime,timestamp和datetime64对象。 import datetime import numpy as np import pandas as pd dt = datetime.datetime(2012, 5, 1) # A strange way to extract a Timestamp object, there's surely a better way? ts = pd.DatetimeIndex([dt])[0] dt64 = np.datetime64(dt) In [7]: dt Out[7]: datetime.datetime(2012, 5, 1, 0, 0) In [8]: ts Out[8]: …