0

如果我有一个float64值的NumPy 数组。我知道这些值以datetime64[ns]格式表示日期。我尝试用熊猫转换它们。但我得到一个ValueError: Inferred frequency 86400N from passed values does not conform to pass frequency N

time = np.array([1420156200.0,1420242600.0,1420329000.0], dtype='float64')
pd.DatetimeIndex(time, freq='ns')

时间值必须是'2015-01-01T23:50:00.000000000', '2015-01-02T23:50:00.000000000', '2015-01-03T23:50:00.000000000'。我该如何存档?谢谢!

4

1 回答 1

1

您可以pd.to_datetime()与 unit 一起使用s,如下所示:

time = np.array([1420156200.0,1420242600.0,1420329000.0], dtype='float64')
pd.to_datetime(time, unit='s')

结果:

DatetimeIndex(['2015-01-01 23:50:00', '2015-01-02 23:50:00',
               '2015-01-03 23:50:00'],
              dtype='datetime64[ns]', freq=None)
于 2021-10-17T12:51:18.273 回答