Pandas Series str | rstrip method
Start your free 7-days trial now!
Pandas Series str.rstrip(~)
method removes the combination of the specified characters that appear from the right of each string in the Series.
Note that a new Series is returned, and the original is kept intact.
Parameters
1. to_strip
| str
or None
| optional
The combination of the characters of to_strip
that appears at the back of each string will be removed. For instance, if to_strip="ab"
, then Aab
and Aba
will both become A
.
By default, trailing whitespaces (including newlines and tabs) will be removed.
Return value
A new Series
or Index
.
Examples
Basic usage
By default, rstrip(~)
removes trailing whitespaces (including newlines and tabs):
0 1 a a2 a3 adtype: object
To confirm that the whitespaces have indeed been stripped, we print the length of each string:
0 01 32 13 1dtype: int64
Specifying to_strip
To remove a combination of the characters "ab"
at the back:
s.str.rstrip("ab")
0 A1 Adtype: object