MCPcopy Index your code
hub / github.com/pydata/xarray / rsplit

Method rsplit

xarray/core/accessor_str.py:2652–2768  ·  view source on GitHub ↗

r""" 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. Para

(
        self,
        dim: Hashable | None,
        sep: str | bytes | Any = None,
        maxsplit: int | Any = -1,
    )

Source from the content-addressed store, hash-verified

2650 )
2651
2652 def rsplit(
2653 self,
2654 dim: Hashable | None,
2655 sep: str | bytes | Any = None,
2656 maxsplit: int | Any = -1,
2657 ) -> DataArray:
2658 r"""
2659 Split strings in a DataArray around the given separator/delimiter `sep`.
2660
2661 Splits the string in the DataArray from the end,
2662 at the specified delimiter string.
2663
2664 If `sep` is array-like, it is broadcast against the array and applied
2665 elementwise.
2666
2667 Parameters
2668 ----------
2669 dim : hashable or None
2670 Name for the dimension to place the results in.
2671 If `None`, place the results as list elements in an object DataArray
2672 sep : str, default: None
2673 String to split on. If ``None`` (the default), split on any whitespace.
2674 If array-like, it is broadcast.
2675 maxsplit : int, default: -1
2676 Limit number of splits in output, starting from the end.
2677 If -1 (the default), return all splits.
2678 The final number of split values may be less than this if there are no
2679 DataArray elements with that many values.
2680
2681 Returns
2682 -------
2683 rsplitted : same type as values or object array
2684
2685 Examples
2686 --------
2687 Create a string DataArray
2688
2689 >>> values = xr.DataArray(
2690 ... [
2691 ... ["abc def", "spam\t\teggs\tswallow", "red_blue"],
2692 ... ["test0\ntest1\ntest2\n\ntest3", "", "abra ka\nda\tbra"],
2693 ... ],
2694 ... dims=["X", "Y"],
2695 ... )
2696
2697 Split once and put the results in a new dimension
2698
2699 >>> values.str.rsplit(dim="splitted", maxsplit=1)
2700 <xarray.DataArray (X: 2, Y: 3, splitted: 2)> Size: 816B
2701 array([[['abc', 'def'],
2702 ['spam\t\teggs', 'swallow'],
2703 ['', 'red_blue']],
2704 <BLANKLINE>
2705 [['test0\ntest1\ntest2', 'test3'],
2706 ['', ''],
2707 ['abra ka\nda', 'bra']]], dtype='<U17')
2708 Dimensions without coordinates: X, Y, splitted
2709

Callers 3

test_splitters_broadcastFunction · 0.80
test_splitters_empty_strFunction · 0.80

Calls 1

_splitterMethod · 0.95

Tested by 3

test_splitters_broadcastFunction · 0.64
test_splitters_empty_strFunction · 0.64