MCPcopy
hub / github.com/pydata/xarray / split

Method split

xarray/core/accessor_str.py:2536–2650  ·  view source on GitHub ↗

r""" Split strings in a DataArray around the given separator/delimiter `sep`. Splits the string in the DataArray from the beginning, at the specified delimiter string. If `sep` is array-like, it is broadcast against the array and applied elementwise.

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

Source from the content-addressed store, hash-verified

2534 )
2535
2536 def split(
2537 self,
2538 dim: Hashable | None,
2539 sep: str | bytes | Any = None,
2540 maxsplit: int = -1,
2541 ) -> DataArray:
2542 r"""
2543 Split strings in a DataArray around the given separator/delimiter `sep`.
2544
2545 Splits the string in the DataArray from the beginning,
2546 at the specified delimiter string.
2547
2548 If `sep` is array-like, it is broadcast against the array and applied
2549 elementwise.
2550
2551 Parameters
2552 ----------
2553 dim : hashable or None
2554 Name for the dimension to place the results in.
2555 If `None`, place the results as list elements in an object DataArray.
2556 sep : str, default: None
2557 String to split on. If ``None`` (the default), split on any whitespace.
2558 If array-like, it is broadcast.
2559 maxsplit : int, default: -1
2560 Limit number of splits in output, starting from the beginning.
2561 If -1 (the default), return all splits.
2562
2563 Returns
2564 -------
2565 splitted : same type as values or object array
2566
2567 Examples
2568 --------
2569 Create a string DataArray
2570
2571 >>> values = xr.DataArray(
2572 ... [
2573 ... ["abc def", "spam\t\teggs\tswallow", "red_blue"],
2574 ... ["test0\ntest1\ntest2\n\ntest3", "", "abra ka\nda\tbra"],
2575 ... ],
2576 ... dims=["X", "Y"],
2577 ... )
2578
2579 Split once and put the results in a new dimension
2580
2581 >>> values.str.split(dim="splitted", maxsplit=1)
2582 <xarray.DataArray (X: 2, Y: 3, splitted: 2)> Size: 864B
2583 array([[['abc', 'def'],
2584 ['spam', 'eggs\tswallow'],
2585 ['red_blue', '']],
2586 <BLANKLINE>
2587 [['test0', 'test1\ntest2\n\ntest3'],
2588 ['', ''],
2589 ['abra', 'ka\nda\tbra']]], dtype='<U18')
2590 Dimensions without coordinates: X, Y, splitted
2591
2592 Split as many times as needed and put the results in a new dimension
2593

Callers 15

make_dsMethod · 0.80
linkcode_resolveFunction · 0.80
update_videosFunction · 0.80
decode_cf_variablesFunction · 0.80
_encode_coordinatesFunction · 0.80
get_chunked_array_typeFunction · 0.80
get_dummiesMethod · 0.80
datatree_child_reprFunction · 0.80
attempt_importFunction · 0.80
getMethod · 0.80
_without_headerFunction · 0.80
_get_virtual_variableFunction · 0.80

Calls 1

_splitterMethod · 0.95

Tested by 10

test_reprMethod · 0.64
test_repr_multiindexMethod · 0.64
netcdfc_versionMethod · 0.64
test__mapping_reprFunction · 0.64
test_splitters_broadcastFunction · 0.64
test_split_emptyFunction · 0.64
test_splitters_empty_strFunction · 0.64
setup_for_testMethod · 0.64