Remove leading and trailing characters. Strip whitespaces (including newlines) or a set of specified characters from each string in the array from left and/or right sides. `to_strip` can either be a ``str`` or array-like of ``str``. If array-like, it will b
(
self, to_strip: str | bytes | Any = None, side: str = "both"
)
| 1558 | return self._apply(func=func, func_args=(pat,), dtype=bool) |
| 1559 | |
| 1560 | def strip( |
| 1561 | self, to_strip: str | bytes | Any = None, side: str = "both" |
| 1562 | ) -> T_DataArray: |
| 1563 | """ |
| 1564 | Remove leading and trailing characters. |
| 1565 | |
| 1566 | Strip whitespaces (including newlines) or a set of specified characters |
| 1567 | from each string in the array from left and/or right sides. |
| 1568 | |
| 1569 | `to_strip` can either be a ``str`` or array-like of ``str``. |
| 1570 | If array-like, it will be broadcast and applied elementwise. |
| 1571 | |
| 1572 | Parameters |
| 1573 | ---------- |
| 1574 | to_strip : str or array-like of str or None, default: None |
| 1575 | Specifying the set of characters to be removed. |
| 1576 | All combinations of this set of characters will be stripped. |
| 1577 | If None then whitespaces are removed. If array-like, it is broadcast. |
| 1578 | side : {"left", "right", "both"}, default: "both" |
| 1579 | Side from which to strip. |
| 1580 | |
| 1581 | Returns |
| 1582 | ------- |
| 1583 | stripped : same type as values |
| 1584 | """ |
| 1585 | if to_strip is not None: |
| 1586 | to_strip = self._stringify(to_strip) |
| 1587 | |
| 1588 | if side == "both": |
| 1589 | func = lambda x, y: x.strip(y) |
| 1590 | elif side == "left": |
| 1591 | func = lambda x, y: x.lstrip(y) |
| 1592 | elif side == "right": |
| 1593 | func = lambda x, y: x.rstrip(y) |
| 1594 | else: # pragma: no cover |
| 1595 | raise ValueError("Invalid side") |
| 1596 | |
| 1597 | return self._apply(func=func, func_args=(to_strip,)) |
| 1598 | |
| 1599 | def lstrip(self, to_strip: str | bytes | Any = None) -> T_DataArray: |
| 1600 | """ |