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,
)
| 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 |