0

If I have a NumPy array of float64 values. I know these values represent dates in format of datetime64[ns]. I try to convert them with pandas. But I get an ValueError: Inferred frequency 86400N from passed values does not conform to passed frequency N

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

The time values must be '2015-01-01T23:50:00.000000000', '2015-01-02T23:50:00.000000000', '2015-01-03T23:50:00.000000000'. How can i archive this? Thanks!

1

1 Answer 1

1

You can use pd.to_datetime() with unit s, as follows:

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

Result:

DatetimeIndex(['2015-01-01 23:50:00', '2015-01-02 23:50:00',
               '2015-01-03 23:50:00'],
              dtype='datetime64[ns]', freq=None)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.