Skip to content

DOC: Updating str_slice docstring #22569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 4, 2018
61 changes: 56 additions & 5 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,17 +1385,68 @@ def str_rsplit(arr, pat=None, n=None):

def str_slice(arr, start=None, stop=None, step=None):
"""
Slice substrings from each element in the Series/Index
Slice substrings from each element in the Series or Index.

Parameters
----------
start : int or None
stop : int or None
step : int or None
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
-------
sliced : Series/Index of objects
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", "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

Equivalent behaviour to:
>>> s.str[0:5:3]
0 kl
1 f
2 cm
dtype: object
"""
obj = slice(start, stop, step)
f = lambda x: x[obj]
Expand Down