From 52bc395c4efc64a66ca1d067ec71912e290bbb08 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 15:16:18 +0200 Subject: [PATCH 1/3] Cleaned up docstring for str_pad and corrected documentation to match behaviour. Added examples --- pandas/core/strings.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index e455c751057d1..d209a80cc4e3e 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1314,8 +1314,8 @@ def str_index(arr, sub, start=0, end=None, side='left'): def str_pad(arr, width, side='left', fillchar=' '): """ - Pad strings in the Series/Index with an additional character to - specified side. + Pad strings in the Series/Index with additional characters on + specified side to fill up to specified width. Parameters ---------- @@ -1323,12 +1323,32 @@ def str_pad(arr, width, side='left', fillchar=' '): Minimum width of resulting string; additional characters will be filled with spaces side : {'left', 'right', 'both'}, default 'left' - fillchar : str + fillchar : str, default ' ' Additional character for filling, default is whitespace Returns ------- - padded : Series/Index of objects + Series or Index of objects + + Examples + -------- + >>> s = pd.Series(["panda", "fox"]) + >>> s + 0 panda + 1 fox + + >>> s.str.pad(10) + 0 panda + 1 fox + + >>> s.str.pad(10, 'right') + 0 panda + 1 fox + + >>> s.str.pad(10, 'both', '-') + 0 --panda--- + 1 ---fox---- + """ if not isinstance(fillchar, compat.string_types): From 5d5b192f409b4c4145a133e75de571d872801833 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 15:18:48 +0200 Subject: [PATCH 2/3] PEP8-ing --- pandas/core/strings.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index d209a80cc4e3e..898a362ad586a 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1336,7 +1336,7 @@ def str_pad(arr, width, side='left', fillchar=' '): >>> s 0 panda 1 fox - + >>> s.str.pad(10) 0 panda 1 fox @@ -1348,7 +1348,6 @@ def str_pad(arr, width, side='left', fillchar=' '): >>> s.str.pad(10, 'both', '-') 0 --panda--- 1 ---fox---- - """ if not isinstance(fillchar, compat.string_types): From f9f8f8be3a6d7b31d0588daf1543fac275ddd038 Mon Sep 17 00:00:00 2001 From: Jesper Dramsch Date: Sat, 1 Sep 2018 16:03:13 +0200 Subject: [PATCH 3/3] Add examples and description for str.slice --- pandas/core/strings.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 898a362ad586a..3796abafada2b 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1404,17 +1404,40 @@ def str_rsplit(arr, pat=None, n=None): def str_slice(arr, start=None, stop=None, step=None): """ - Slice substrings from each element in the Series/Index + Slice substrings from each element in the Series or Index Parameters ---------- start : int or None + Start position for slice operation stop : int or None + Stop position for slice operation step : int or None + Step size for slice operation Returns ------- - sliced : Series/Index of objects + Series or Index of object + Series or Index containing sliced substring from original string + + Examples + -------- + >>> s = pd.Series(["panda", "fox"]) + >>> s + 0 panda + 1 fox + + >>> s.str.slice(start=2) + 0 nda + 1 x + + >>> s.str.slice(stop=2) + 0 pa + 1 fo + + >>> s.str.slice(step=2) + 0 pna + 1 fx """ obj = slice(start, stop, step) f = lambda x: x[obj]