Home > Enterprise >  How to convert a single year to type NumPy datetime
How to convert a single year to type NumPy datetime

Time:02-03

I need to overcome a mapping related error TypeError: input must have type NumPy datetime. I have time axis with following attributes and I only have single year data.

In [26]: times[t]


Out [26]: xarray.DataArray 'time'

    array(1992.)

    Coordinates:
        time        ()        float64        1.992e 03

    Attributes:

    standard_name :     time
    units :             year as %Y.%f
    calendar :          proleptic_gregorian
    axis :              T

How can I convert into Numpy datatime?

I tried the following, but didn't work.

np.datetime_as_string(times[t],timezone='UTC')

Any help/advice is highly appreciated. Thanks in advance!

CodePudding user response:

Just like pandas, numpy has also a datetime numpy.datetime64().Have a look in the following documenation.

https://numpy.org/doc/stable/reference/arrays.datetime.html

  •  Tags:  
  • Related