# xarray.DataArray.str.rsplit

#### DataArray.str.rsplit(dim, sep=None, maxsplit=-1)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/accessor_str.py#L2654-L2770)

Split strings in a DataArray around the given separator/delimiter sep.

Splits the string in the DataArray from the end,
at the specified delimiter string.

If sep is array-like, it is broadcast against the array and applied
elementwise.

* **Parameters:**
  * **dim** ([hashable](../user-guide/terminology.html.md#term-name) or [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Name for the dimension to place the results in.
    If None, place the results as list elements in an object DataArray
  * **sep** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str), *default*: [`None`](https://docs.python.org/3/builtins/constants.html#None)) – String to split on. If `None` (the default), split on any whitespace.
    If array-like, it is broadcast.
  * **maxsplit** ([`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `-1`) – Limit number of splits in output, starting from the end.
    If -1 (the default), return all splits.
    The final number of split values may be less than this if there are no
    DataArray elements with that many values.
* **Returns:**
  **rsplitted** (`same type as values` or `object array`)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('de6a990b-0205-4c58-b1fa-2724684439f7','ab2de5f7-9903-4b69-9626-b3a6c60bb3ae','41100240-c6fe-4df6-8f28-aaaa36ab1827','../lite/tree/../notebooks/index.html?path=fd49e723_3cda_4733_beb4_80c3e8581f47.ipynb','None')">Try it in your browser!</button></div>

Create a string DataArray

```pycon
>>> values = xr.DataArray(
...     [
...         ["abc def", "spam\t\teggs\tswallow", "red_blue"],
...         ["test0\ntest1\ntest2\n\ntest3", "", "abra  ka\nda\tbra"],
...     ],
...     dims=["X", "Y"],
... )
```

Split once and put the results in a new dimension

```pycon
>>> values.str.rsplit(dim="splitted", maxsplit=1)
<xarray.DataArray (X: 2, Y: 3, splitted: 2)> Size: 816B
array([[['abc', 'def'],
        ['spam\t\teggs', 'swallow'],
        ['', 'red_blue']],

       [['test0\ntest1\ntest2', 'test3'],
        ['', ''],
        ['abra  ka\nda', 'bra']]], dtype='<U17')
Dimensions without coordinates: X, Y, splitted
```

Split as many times as needed and put the results in a new dimension

```pycon
>>> values.str.rsplit(dim="splitted")
<xarray.DataArray (X: 2, Y: 3, splitted: 4)> Size: 768B
array([[['', '', 'abc', 'def'],
        ['', 'spam', 'eggs', 'swallow'],
        ['', '', '', 'red_blue']],

       [['test0', 'test1', 'test2', 'test3'],
        ['', '', '', ''],
        ['abra', 'ka', 'da', 'bra']]], dtype='<U8')
Dimensions without coordinates: X, Y, splitted
```

Split once and put the results in lists

```pycon
>>> values.str.rsplit(dim=None, maxsplit=1)
<xarray.DataArray (X: 2, Y: 3)> Size: 48B
array([[list(['abc', 'def']), list(['spam\t\teggs', 'swallow']),
        list(['red_blue'])],
       [list(['test0\ntest1\ntest2', 'test3']), list([]),
        list(['abra  ka\nda', 'bra'])]], dtype=object)
Dimensions without coordinates: X, Y
```

Split as many times as needed and put the results in a list

```pycon
>>> values.str.rsplit(dim=None)
<xarray.DataArray (X: 2, Y: 3)> Size: 48B
array([[list(['abc', 'def']), list(['spam', 'eggs', 'swallow']),
        list(['red_blue'])],
       [list(['test0', 'test1', 'test2', 'test3']), list([]),
        list(['abra', 'ka', 'da', 'bra'])]], dtype=object)
Dimensions without coordinates: X, Y
```

Split only on spaces

```pycon
>>> values.str.rsplit(dim="splitted", sep=" ")
<xarray.DataArray (X: 2, Y: 3, splitted: 3)> Size: 2kB
array([[['', 'abc', 'def'],
        ['', '', 'spam\t\teggs\tswallow'],
        ['', '', 'red_blue']],

       [['', '', 'test0\ntest1\ntest2\n\ntest3'],
        ['', '', ''],
        ['abra', '', 'ka\nda\tbra']]], dtype='<U24')
Dimensions without coordinates: X, Y, splitted
```

<div id="41100240-c6fe-4df6-8f28-aaaa36ab1827" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('de6a990b-0205-4c58-b1fa-2724684439f7','41100240-c6fe-4df6-8f28-aaaa36ab1827')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('de6a990b-0205-4c58-b1fa-2724684439f7','41100240-c6fe-4df6-8f28-aaaa36ab1827')">Open In Tab</button></div><div id="ab2de5f7-9903-4b69-9626-b3a6c60bb3ae" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### SEE ALSO
[`DataArray.str.split`](xarray.DataArray.str.split.html.md#xarray.DataArray.str.split), [`str.rsplit`](https://docs.python.org/3/builtins/stdtypes.html#str.rsplit), [`pandas.Series.str.rsplit`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.rsplit.html#pandas.Series.str.rsplit)
