🍾 Xarray is now 10 years old! 🎉

xarray.DataArray.str.slice_replace

xarray.DataArray.str.slice_replace#

DataArray.str.slice_replace(start=None, stop=None, repl='')[source]#

Replace a positional slice of a string with another value.

If start, stop, or ‘repl` is array-like, they are broadcast against the array and applied elementwise.

Parameters:
  • start (int or array-like of int, optional) – Left index position to use for the slice. If not specified (None), the slice is unbounded on the left, i.e. slice from the start of the string. If array-like, it is broadcast.

  • stop (int or array-like of int, optional) – Right index position to use for the slice. If not specified (None), the slice is unbounded on the right, i.e. slice until the end of the string. If array-like, it is broadcast.

  • repl (str or array-like of str, default: "") – String for replacement. If not specified, the sliced region is replaced with an empty string. If array-like, it is broadcast.

Returns:

replaced (same type as values)