Remove leading and trailing characters.

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

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.


Series/Index of objects


  • 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.


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

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

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

$ python ./series/str/
0    Ant
1    Bee
2    Cat
dtype: object

See also


Remove leading and trailing characters in Series.


Remove leading characters in Series.


Remove trailing characters in Series.