Skip to main content
`Ctrl`+`K`

# pandas.Series.str.slice

Series.str.slice(start=None, stop=None, step=None)

  Slice substrings from each element in the Series or Index.

  Slicing substrings from strings in a Series or Index helps extract specific portions of data, making it easier to analyze or manipulate text. This is useful for tasks like parsing structured text fields or isolating parts of strings with a consistent format.

  Parameters:
    start int, optional

      Start position for slice operation.

    stop int, optional

      Stop position for slice operation.

    step int, optional

      Step size for slice operation.

  Returns:
    Series or Index of object

      Series or Index from sliced substring from original string object.

  See also

  `Series.str.slice_replace`

    Replace a slice with a string.

  `Series.str.get`

    Return element at position. Equivalent to Series.str.slice(start=i, stop=i+1) with i being the position.

  Examples

      >>> s = pd.Series(["koala", "dog", "chameleon"])
      >>> s
      0        koala
      1          dog
      2    chameleon
      dtype: str

      >>> s.str.slice(start=1)
      0        oala
      1          og
      2    hameleon
      dtype: str

      >>> s.str.slice(start=-1)
      0           a
      1           g
      2           n
      dtype: str

      >>> s.str.slice(stop=2)
      0    ko
      1    do
      2    ch
      dtype: str

      >>> s.str.slice(step=2)
      0      kaa
      1       dg
      2    caeen
      dtype: str

      >>> s.str.slice(start=0, stop=5, step=3)
      0    kl
      1     d
      2    cm
      dtype: str

  Equivalent behaviour to:

      >>> s.str[0:5:3]
      0    kl
      1     d
      2    cm
      dtype: str