MCPcopy
hub / github.com/pandas-dev/pandas / rstrip

Method rstrip

pandas/core/strings/accessor.py:2632–2708  ·  view source on GitHub ↗

Remove trailing characters. Strip whitespaces (including newlines) or a set of specified characters from each string in the Series/Index from right side. Replaces any non-strings in Series with NaNs. Equivalent to :meth:`str.rstrip`. Parameters

(self, to_strip=None)

Source from the content-addressed store, hash-verified

2630
2631 @forbid_nonstring_types(["bytes"])
2632 def rstrip(self, to_strip=None):
2633 """
2634 Remove trailing characters.
2635
2636 Strip whitespaces (including newlines) or a set of specified characters
2637 from each string in the Series/Index from right side.
2638 Replaces any non-strings in Series with NaNs.
2639 Equivalent to :meth:`str.rstrip`.
2640
2641 Parameters
2642 ----------
2643 to_strip : str or None, default None
2644 Specifying the set of characters to be removed.
2645 All combinations of this set of characters will be stripped.
2646 If None then whitespaces are removed.
2647
2648 Returns
2649 -------
2650 Series or Index of object
2651 Series or Index with the strings being stripped from the right side.
2652
2653 See Also
2654 --------
2655 Series.str.strip : Remove leading and trailing characters in Series/Index.
2656 Series.str.lstrip : Remove leading characters in Series/Index.
2657 Series.str.rstrip : Remove trailing characters in Series/Index.
2658
2659 Examples
2660 --------
2661 >>> s = pd.Series(["1. Ant. ", "2. Bee!\\n", "3. Cat?\\t", np.nan, 10, True])
2662 >>> s
2663 0 1. Ant.
2664 1 2. Bee!\\n
2665 2 3. Cat?\\t
2666 3 NaN
2667 4 10
2668 5 True
2669 dtype: object
2670
2671 >>> s.str.strip()
2672 0 1. Ant.
2673 1 2. Bee!
2674 2 3. Cat?
2675 3 NaN
2676 4 NaN
2677 5 NaN
2678 dtype: object
2679
2680 >>> s.str.lstrip("123.")
2681 0 Ant.
2682 1 Bee!\\n
2683 2 Cat?\\t
2684 3 NaN
2685 4 NaN
2686 5 NaN
2687 dtype: object
2688
2689 >>> s.str.rstrip(".!? \\n\\t")

Callers 15

time_rstripMethod · 0.80
resolve_nameMethod · 0.80
_str_rstripMethod · 0.80
__repr__Method · 0.80
_repr_2dMethod · 0.80
_get_repr_footerMethod · 0.80
melt_stubFunction · 0.80
__repr__Method · 0.80
walkMethod · 0.80
readMethod · 0.80

Calls 2

_wrap_resultMethod · 0.95
_str_rstripMethod · 0.45

Tested by 4

test_empty_str_methodsFunction · 0.64
test_repr_unicodeMethod · 0.64
expected_htmlFunction · 0.64