Skip to content

Commit d430195

Browse files
JesperDramschdatapythonista
authored andcommitted
DOC: Updating str_slice docstring (#22569)
1 parent f4dfcfd commit d430195

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

pandas/core/strings.py

+57-5
Original file line numberDiff line numberDiff line change
@@ -1437,17 +1437,69 @@ def str_rsplit(arr, pat=None, n=None):
14371437

14381438
def str_slice(arr, start=None, stop=None, step=None):
14391439
"""
1440-
Slice substrings from each element in the Series/Index
1440+
Slice substrings from each element in the Series or Index.
14411441
14421442
Parameters
14431443
----------
1444-
start : int or None
1445-
stop : int or None
1446-
step : int or None
1444+
start : int, optional
1445+
Start position for slice operation.
1446+
stop : int, optional
1447+
Stop position for slice operation.
1448+
step : int, optional
1449+
Step size for slice operation.
14471450
14481451
Returns
14491452
-------
1450-
sliced : Series/Index of objects
1453+
Series or Index of object
1454+
Series or Index from sliced substring from original string object.
1455+
1456+
See Also
1457+
--------
1458+
Series.str.slice_replace : Replace a slice with a string.
1459+
Series.str.get : Return element at position.
1460+
Equivalent to `Series.str.slice(start=i, stop=i+1)` with `i`
1461+
being the position.
1462+
1463+
Examples
1464+
--------
1465+
>>> s = pd.Series(["koala", "fox", "chameleon"])
1466+
>>> s
1467+
0 koala
1468+
1 fox
1469+
2 chameleon
1470+
dtype: object
1471+
1472+
>>> s.str.slice(start=1)
1473+
0 oala
1474+
1 ox
1475+
2 hameleon
1476+
dtype: object
1477+
1478+
>>> s.str.slice(stop=2)
1479+
0 ko
1480+
1 fo
1481+
2 ch
1482+
dtype: object
1483+
1484+
>>> s.str.slice(step=2)
1485+
0 kaa
1486+
1 fx
1487+
2 caeen
1488+
dtype: object
1489+
1490+
>>> s.str.slice(start=0, stop=5, step=3)
1491+
0 kl
1492+
1 f
1493+
2 cm
1494+
dtype: object
1495+
1496+
Equivalent behaviour to:
1497+
1498+
>>> s.str[0:5:3]
1499+
0 kl
1500+
1 f
1501+
2 cm
1502+
dtype: object
14511503
"""
14521504
obj = slice(start, stop, step)
14531505
f = lambda x: x[obj]

0 commit comments

Comments
 (0)