pandas.Series.str.rstrip

Remove leading and trailing characters.

Strip whitespaces (including newlines) or a set of specified characters from each string in the Series/Index from right side. Equivalent to str.rstrip().

param to_strip
str or None, default None

Specifying the set of characters to be removed. All combinations of this set of characters will be stripped. If None then whitespaces are removed.

return

Series/Index of objects

Limitations

  • All values in Series equal to None are converted to NaNs.

  • This function may reveal slower performance than Pandas* on user system. Users should exercise a tradeoff

    between staying in JIT-region with that function or going back to interpreter mode.

Examples

Remove leading and trailing characters.
import pandas as pd
from numba import njit


@njit
def series_str_rstrip():
    series = pd.Series(['1. Ant.  ', '2. Bee!\n', '3. Cat?\t'])

    return series.str.rstrip('.!? \n\t')


print(series_str_rstrip())
$ python ./series/str/series_str_rstrip.py
0    1. Ant
1    2. Bee
2    3. Cat
dtype: object

See also

Series.str.strip

Remove leading and trailing characters in Series.

Series.str.lstrip

Remove leading characters in Series.

Series.str.strip

Remove trailing characters in Series.