From 43106715232204be7f219ccf8613cfab0f772e74 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Tue, 18 Sep 2018 14:40:45 +0200 Subject: [PATCH] DOC: Updating str_repeat docstring (#22571) --- pandas/core/strings.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 08709d15c48bf..b46c6a4557ff3 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -678,20 +678,42 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=True): def str_repeat(arr, repeats): """ - Duplicate each string in the Series/Index by indicated number - of times. + Duplicate each string in the Series or Index. Parameters ---------- - repeats : int or array - Same value for all (int) or different value per (array) + repeats : int or sequence of int + Same value for all (int) or different value per (sequence). Returns ------- - repeated : Series/Index of objects + Series or Index of object + Series or Index of repeated string objects specified by + input parameter repeats. + + Examples + -------- + >>> s = pd.Series(['a', 'b', 'c']) + >>> s + 0 a + 1 b + 2 c + + Single int repeats string in Series + + >>> s.str.repeat(repeats=2) + 0 aa + 1 bb + 2 cc + + Sequence of int repeats corresponding string in Series + + >>> s.str.repeat(repeats=[1, 2, 3]) + 0 a + 1 bb + 2 ccc """ if is_scalar(repeats): - def rep(x): try: return compat.binary_type.__mul__(x, repeats)