0
data['RealTime'][:,0]
Out[23]: 
array([datetime.datetime(2017, 9, 12, 18, 13, 8, 826000),
       datetime.datetime(2017, 9, 12, 18, 13, 8, 846000),
       datetime.datetime(2017, 9, 12, 18, 13, 8, 866000), ...,
       datetime.datetime(2017, 9, 12, 18, 30, 40, 186000),
       datetime.datetime(2017, 9, 12, 18, 30, 40, 206000),
       datetime.datetime(2017, 9, 12, 18, 30, 40, 226000)], dtype=object)

how can I convert into an array of dtype datetime?

1
  • Is this Pandas or Numpy? Commented Sep 19, 2017 at 7:54

1 Answer 1

3

I know you have pandas, so you can just use pd.to_datetime:

out = pd.to_datetime(array)
print(out)

DatetimeIndex(['2017-09-12 18:13:08.826000', '2017-09-12 18:13:08.846000',
               '2017-09-12 18:13:08.866000', '2017-09-12 18:30:40.186000',
               '2017-09-12 18:30:40.206000', '2017-09-12 18:30:40.226000'],
              dtype='datetime64[ns]', freq=None)

You can retrieve a numpy array from out by accessing out.values.


With numpy, you'd do the same thing using astype:

out = array.astype("datetime64[ns]")
print(out)

array(['2017-09-12T18:13:08.826000000', '2017-09-12T18:13:08.846000000',
       '2017-09-12T18:13:08.866000000', '2017-09-12T18:30:40.186000000',
       '2017-09-12T18:30:40.206000000', '2017-09-12T18:30:40.226000000'], dtype='datetime64[ns]')
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.