Skip to content

Commit 8b9fdbe

Browse files
committed
Update the pandas.Series.str.repeat docstring
1 parent 6d610a4 commit 8b9fdbe

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

pandas/core/strings.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,17 +594,59 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=True):
594594

595595
def str_repeat(arr, repeats):
596596
"""
597-
Duplicate each string in the Series/Index by indicated number
598-
of times.
597+
Duplicate each string repeated by indicated number of times.
599598
600599
Parameters
601600
----------
602601
repeats : int or array
603-
Same value for all (int) or different value per (array)
602+
Same value for all (int) or different value per (array).
604603
605604
Returns
606605
-------
607606
repeated : Series/Index of objects
607+
Same type as the original object
608+
609+
Examples
610+
--------
611+
>>> s = pd.Series(['a', 'b', 'c', 'd', 'e'])
612+
613+
Using same value for all:
614+
615+
>>> s.str.repeat(4)
616+
0 aaaa
617+
1 bbbb
618+
2 cccc
619+
3 dddd
620+
4 eeee
621+
dtype: object
622+
623+
Using different value per element:
624+
625+
>>> s.str.repeat([3, 2, 5, 1, 4])
626+
0 aaa
627+
1 bb
628+
2 ccccc
629+
3 d
630+
4 eeee
631+
dtype: object
632+
633+
Passing zero or negative integer will return an empty string
634+
635+
>>> s.str.repeat([0, 0, -2, -1, 0])
636+
0
637+
1
638+
2
639+
3
640+
4
641+
dtype: object
642+
643+
Notes
644+
--------
645+
A passed value of zero or negative integer will return an empty string.
646+
647+
See also
648+
--------
649+
numpy.ndarray.repeat: Repeat elements of an array.
608650
"""
609651
if is_scalar(repeats):
610652

0 commit comments

Comments
 (0)