2

I convert the numpy array of datetime to a list but i need to reverse them into datetime format.

> v_date
[1642636800000000000,
 1649203200000000000,
 1649462400000000000,
 1650326400000000000,
...
 1668816000000000000,
 1669593600000000000,
 1671753600000000000]

the xaxis of matplotlib chart need to be small integer or has the datetime format. it raise this error: OverflowError: int too big to convert

1 Answers1

4

You can use pandas.to_datetime:

import pandas as pd

v_date = [1642636800000000000,
          1649203200000000000,
          1649462400000000000,
          1650326400000000000,
          1668816000000000000,
          1669593600000000000,
          1671753600000000000]

out = pd.to_datetime(v_date)

Output:

DatetimeIndex(['2022-01-20', '2022-04-06', '2022-04-09', '2022-04-19', '2022-11-19', '2022-11-28', '2022-12-23'], dtype='datetime64[ns]', freq=None)
mozway
  • 194,879
  • 13
  • 39
  • 75