pandas.Series.str.slice
-
Series.str.slice(start=None, stop=None, step=None)[source] -
Вырезание подстрок из каждого элемента в Series или Index.
Параметры: -
start : int, optional -
Начальная позиция для операции среза.
-
stop : int, optional -
Конечная позиция для операции среза.
-
step : int, optional -
Шаг для операции среза.
Возвращает: - Series или Index объекта
-
Series или Index, полученный из вырезанной подстроки из исходного строкового объекта.
См. также
-
Series.str.slice_replace - Замена среза строкой.
-
Series.str.get - Возвращает элемент в позиции. Эквивалентно
Series.str.slice(start=i, stop=i+1)сiв качестве позиции.
Примеры
>>> s = pd.Series(["koala", "fox", "chameleon"]) >>> s 0 koala 1 fox 2 chameleon dtype: object
>>> s.str.slice(start=1) 0 oala 1 ox 2 hameleon dtype: object
>>> s.str.slice(stop=2) 0 ko 1 fo 2 ch dtype: object
>>> s.str.slice(step=2) 0 kaa 1 fx 2 caeen dtype: object
>>> s.str.slice(start=0, stop=5, step=3) 0 kl 1 f 2 cm dtype: object
Эквивалентное поведение:
>>> s.str[0:5:3] 0 kl 1 f 2 cm dtype: object
-
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.24.2/reference/api/pandas.Series.str.slice.html