TIME IN XARRAY

Chris Angelico rosuav at gmail.com
Thu Apr 15 14:20:15 EDT 2021


On Fri, Apr 16, 2021 at 4:16 AM Jorge Conforte <jorge.conforte at inpe.br> wrote:
> I'm using xarray to read netcdf data and I had to time in my data the
> values:
>
> xarray.DataArray 'time' (time: 507)>
> array(['1979-01-01T00:00:00.000000000', '1979-02-01T00:00:00.000000000',
>         '1979-03-01T00:00:00.000000000', ...,
> '2021-01-01T00:00:00.000000000',
>         '2021-02-01T00:00:00.000000000', '2021-03-01T00:00:00.000000000'],
>        dtype='datetime64[ns]')
>
>
> Please, how can I get the years and months values from this array.
>

Looks like your "time" values are ISO-8601 dates, stored as strings.
You should be able to parse them easily by hand, or hand them to
datetime.datetime.fromisoformat().

ChrisA


More information about the Python-list mailing list