Skip to content

Commit 6ab42c6

Browse files
committed
Update the pandas.Series.str.repeat docstring
1 parent 62d9f8c commit 6ab42c6

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

pandas/core/strings.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,17 +678,44 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=True):
678678

679679
def str_repeat(arr, repeats):
680680
"""
681-
Duplicate each string in the Series/Index by indicated number
682-
of times.
681+
Duplicate each string repeated by indicated number of times.
682+
683+
Duplicate each string in the Series/Index by indicated number of times.
684+
A passed value of zero or negative integer will return an empty string.
683685
684686
Parameters
685687
----------
686-
repeats : int or array
687-
Same value for all (int) or different value per (array)
688+
repeats : int or array-like
689+
Same value for all (int) or different value per (array).
688690
689691
Returns
690692
-------
691-
repeated : Series/Index of objects
693+
Series or Index
694+
Same type as the original object
695+
696+
Examples
697+
--------
698+
>>> s = pd.Series(['a', 'b', 'c', 'd', 'e'])
699+
700+
Using same value for all:
701+
702+
>>> s.str.repeat(4)
703+
0 aaaa
704+
1 bbbb
705+
2 cccc
706+
3 dddd
707+
4 eeee
708+
dtype: object
709+
710+
Using different value per element:
711+
712+
>>> s.str.repeat([-3, 0, 5, 1, 4])
713+
0
714+
1
715+
2 ccccc
716+
3 d
717+
4 eeee
718+
dtype: object
692719
"""
693720
if is_scalar(repeats):
694721

0 commit comments

Comments
 (0)