From 15af4a67e787c2bdb74cf19d61e1e3f490352f08 Mon Sep 17 00:00:00 2001 From: "sahilc.mac" Date: Sat, 10 Mar 2018 20:03:02 +0530 Subject: [PATCH 1/3] rpartition docstring is modified --- pandas/core/strings.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index fac607f4621a8..41bf95bdc58f1 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1611,7 +1611,9 @@ def rsplit(self, pat=None, n=-1, expand=False): return self._wrap_result(result, expand=expand) _shared_docs['str_partition'] = (""" - Split the string at the %(side)s occurrence of `sep`, and return 3 elements + Split the string at the %(side)s occurrence of `sep`. + + This method splits the string at the %(side)s occurrence of `sep`, and return 3 elements containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return %(return)s. @@ -1621,8 +1623,8 @@ def rsplit(self, pat=None, n=-1, expand=False): pat : string, default whitespace String to split on. expand : bool, default True - * If True, return DataFrame/MultiIndex expanding dimensionality. - * If False, return Series/Index. + If True, return DataFrame/MultiIndex expanding dimensionality. + If False, return Series/Index. Returns ------- @@ -1635,7 +1637,8 @@ def rsplit(self, pat=None, n=-1, expand=False): Examples -------- - >>> s = Series(['A_B_C', 'D_E_F', 'X']) + >>> s = pd.Series(['A_B_C', 'D_E_F', 'X']) + >>> s 0 A_B_C 1 D_E_F 2 X From 5a17e99d422d218fb12d12ffb91eab7a61eedc9f Mon Sep 17 00:00:00 2001 From: "sahilc.mac" Date: Sat, 10 Mar 2018 20:12:32 +0530 Subject: [PATCH 2/3] rpartition docstring is modified --- pandas/core/strings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 41bf95bdc58f1..8863cdd37debc 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1613,9 +1613,9 @@ def rsplit(self, pat=None, n=-1, expand=False): _shared_docs['str_partition'] = (""" Split the string at the %(side)s occurrence of `sep`. - This method splits the string at the %(side)s occurrence of `sep`, and return 3 elements - containing the part before the separator, the separator itself, - and the part after the separator. + This method splits the string at the %(side)s occurrence of `sep`, + and return 3 elements containing the part before the separator, + the separator itself, and the part after the separator. If the separator is not found, return %(return)s. Parameters From 8d5ef6e6a27ec56e7a21cdb1ce1440219b2149f5 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sun, 8 Jul 2018 12:16:21 -0500 Subject: [PATCH 3/3] Fixing couple of typos, and improving the See Also and Examples section --- pandas/core/strings.py | 68 +++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index b987e6c57355b..ecc8c266b136d 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -2343,13 +2343,13 @@ def rsplit(self, pat=None, n=-1, expand=False): Split the string at the %(side)s occurrence of `sep`. This method splits the string at the %(side)s occurrence of `sep`, - and return 3 elements containing the part before the separator, + and returns 3 elements containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return %(return)s. Parameters ---------- - pat : string, default whitespace + pat : str, default whitespace String to split on. expand : bool, default True If True, return DataFrame/MultiIndex expanding dimensionality. @@ -2357,33 +2357,65 @@ def rsplit(self, pat=None, n=-1, expand=False): Returns ------- - split : DataFrame/MultiIndex or Series/Index of objects + DataFrame/MultiIndex or Series/Index of objects See Also -------- %(also)s + Series.str.split : Split strings around given separators. + str.partition : Standard library version. Examples -------- - >>> s = pd.Series(['A_B_C', 'D_E_F', 'X']) + >>> s = pd.Series(['Linda van der Berg', 'George Pitt-Rivers']) >>> s - 0 A_B_C - 1 D_E_F - 2 X + 0 Linda van der Berg + 1 George Pitt-Rivers dtype: object - >>> s.str.partition('_') - 0 1 2 - 0 A _ B_C - 1 D _ E_F - 2 X - - >>> s.str.rpartition('_') - 0 1 2 - 0 A_B _ C - 1 D_E _ F - 2 X + >>> s.str.partition() + 0 1 2 + 0 Linda van der Berg + 1 George Pitt-Rivers + + To partition by the last space instead of the first one: + + >>> s.str.rpartition() + 0 1 2 + 0 Linda van der Berg + 1 George Pitt-Rivers + + To partition by something different than a space: + + >>> s.str.partition('-') + 0 1 2 + 0 Linda van der Berg + 1 George Pitt - Rivers + + To return a Series containining tuples instead of a DataFrame: + + >>> s.str.partition('-', expand=False) + 0 (Linda van der Berg, , ) + 1 (George Pitt, -, Rivers) + dtype: object + + Also available on indices: + + >>> idx = pd.Index(['X 123', 'Y 999']) + >>> idx + Index(['X 123', 'Y 999'], dtype='object') + + Which will create a MultiIndex: + + >>> idx.str.partition() + MultiIndex(levels=[['X', 'Y'], [' '], ['123', '999']], + labels=[[0, 1], [0, 0], [0, 1]]) + + Or an index with tuples with ``expand=False``: + + >>> idx.str.partition(expand=False) + Index([('X', ' ', '123'), ('Y', ' ', '999')], dtype='object') """) @Appender(_shared_docs['str_partition'] % {