recommended method to update variable values #6575
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
you should be able to use In [9]: ds["time"] = ds["time"].copy(data=[np.datetime64(ds["time"].data[0].astype(str)[:-1])])
...: ds
Out[9]:
<xarray.Dataset>
Dimensions: (x: 2, y: 2, time_idx: 1)
Coordinates:
lon (x, y) float64 -99.83 -99.32 -99.79 -99.23
lat (x, y) float64 42.25 42.21 42.63 42.59
* time_idx (time_idx) int64 15
Dimensions without coordinates: x, y
Data variables:
temperature (x, y, time_idx) float64 26.84 -2.025 17.72 3.238
time (time_idx) datetime64[ns] 2019-01-11T05:26:31.323722 but do note that while I get a segfault with edit: if you don't want to modify in-place, you can also use In [7]: ds.assign({"time": lambda ds_: ds_["time"].astype(str).astype(np.datetime64)})
Out[7]:
<xarray.Dataset>
Dimensions: (x: 2, y: 2, time_idx: 1)
Coordinates:
lon (x, y) float64 -99.83 -99.32 -99.79 -99.23
lat (x, y) float64 42.25 42.21 42.63 42.59
* time_idx (time_idx) int64 15
Dimensions without coordinates: x, y
Data variables:
temperature (x, y, time_idx) float64 14.82 27.88 16.31 3.407
time (time_idx) datetime64[ns] 2019-01-11T05:26:31.323722 |
Beta Was this translation helpful? Give feedback.
-
regarding the deprecation: the |
Beta Was this translation helpful? Give feedback.
you should be able to use
copy(data=...)
:but do note that while I get a segfault with
ds["time"].astype(np.datetime64)
,ds["time"].astype(str).astype(np.datetime64)
…