I need to apply a very simple \'match statement\' to the values in an xarray array:
If you are happy to load your data in-memory as a NumPy array, you can modify the DataArray values in place with NumPy:
date_by_items.values[date_by_items.values > 0] = 2
The cleanest way to handle this would be if xarray supported the other
argument to where
, but we haven't implemented that yet (hopefully soon -- the groundwork has been laid!). When that works, you'll be able to write date_by_items.where(date_by_items > 0, 2)
.
Either way, you'll need to do this twice to apply both your criteria.