Skip to content

Commit a924e45

Browse files
committed
Update the pandas.Series.str.repeat docstring
1 parent db97089 commit a924e45

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

pandas/core/strings.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,17 +678,45 @@ 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+
Series or Index of repeated string objects specified by
695+
input parameter repeats.
696+
697+
Examples
698+
--------
699+
>>> s = pd.Series(['a', 'b', 'c', 'd', 'e'])
700+
701+
Using same value for all:
702+
703+
>>> s.str.repeat(repeats=4)
704+
0 aaaa
705+
1 bbbb
706+
2 cccc
707+
3 dddd
708+
4 eeee
709+
dtype: object
710+
711+
Using different value per element:
712+
713+
>>> s.str.repeat(repeats=[-2, -1, 0, 1, 2])
714+
0
715+
1
716+
2
717+
3 d
718+
4 ee
719+
dtype: object
692720
"""
693721
if is_scalar(repeats):
694722

0 commit comments

Comments
 (0)