Skip to content

Commit 9e1f6fd

Browse files
schopra6datapythonista
authored andcommitted
DOC: update the pandas.Series.str.rpartition() docstring (Delhi) (pandas-dev#20199)
* rpartition docstring is modified * rpartition docstring is modified * Fixing couple of typos, and improving the See Also and Examples section
1 parent c697ca6 commit 9e1f6fd

File tree

1 file changed

+57
-22
lines changed

1 file changed

+57
-22
lines changed

pandas/core/strings.py

+57-22
Original file line numberDiff line numberDiff line change
@@ -2340,47 +2340,82 @@ def rsplit(self, pat=None, n=-1, expand=False):
23402340
return self._wrap_result(result, expand=expand)
23412341

23422342
_shared_docs['str_partition'] = ("""
2343-
Split the string at the %(side)s occurrence of `sep`, and return 3 elements
2344-
containing the part before the separator, the separator itself,
2345-
and the part after the separator.
2343+
Split the string at the %(side)s occurrence of `sep`.
2344+
2345+
This method splits the string at the %(side)s occurrence of `sep`,
2346+
and returns 3 elements containing the part before the separator,
2347+
the separator itself, and the part after the separator.
23462348
If the separator is not found, return %(return)s.
23472349
23482350
Parameters
23492351
----------
2350-
pat : string, default whitespace
2352+
pat : str, default whitespace
23512353
String to split on.
23522354
expand : bool, default True
2353-
* If True, return DataFrame/MultiIndex expanding dimensionality.
2354-
* If False, return Series/Index.
2355+
If True, return DataFrame/MultiIndex expanding dimensionality.
2356+
If False, return Series/Index.
23552357
23562358
Returns
23572359
-------
2358-
split : DataFrame/MultiIndex or Series/Index of objects
2360+
DataFrame/MultiIndex or Series/Index of objects
23592361
23602362
See Also
23612363
--------
23622364
%(also)s
2365+
Series.str.split : Split strings around given separators.
2366+
str.partition : Standard library version.
23632367
23642368
Examples
23652369
--------
23662370
2367-
>>> s = Series(['A_B_C', 'D_E_F', 'X'])
2368-
0 A_B_C
2369-
1 D_E_F
2370-
2 X
2371+
>>> s = pd.Series(['Linda van der Berg', 'George Pitt-Rivers'])
2372+
>>> s
2373+
0 Linda van der Berg
2374+
1 George Pitt-Rivers
23712375
dtype: object
23722376
2373-
>>> s.str.partition('_')
2374-
0 1 2
2375-
0 A _ B_C
2376-
1 D _ E_F
2377-
2 X
2378-
2379-
>>> s.str.rpartition('_')
2380-
0 1 2
2381-
0 A_B _ C
2382-
1 D_E _ F
2383-
2 X
2377+
>>> s.str.partition()
2378+
0 1 2
2379+
0 Linda van der Berg
2380+
1 George Pitt-Rivers
2381+
2382+
To partition by the last space instead of the first one:
2383+
2384+
>>> s.str.rpartition()
2385+
0 1 2
2386+
0 Linda van der Berg
2387+
1 George Pitt-Rivers
2388+
2389+
To partition by something different than a space:
2390+
2391+
>>> s.str.partition('-')
2392+
0 1 2
2393+
0 Linda van der Berg
2394+
1 George Pitt - Rivers
2395+
2396+
To return a Series containining tuples instead of a DataFrame:
2397+
2398+
>>> s.str.partition('-', expand=False)
2399+
0 (Linda van der Berg, , )
2400+
1 (George Pitt, -, Rivers)
2401+
dtype: object
2402+
2403+
Also available on indices:
2404+
2405+
>>> idx = pd.Index(['X 123', 'Y 999'])
2406+
>>> idx
2407+
Index(['X 123', 'Y 999'], dtype='object')
2408+
2409+
Which will create a MultiIndex:
2410+
2411+
>>> idx.str.partition()
2412+
MultiIndex(levels=[['X', 'Y'], [' '], ['123', '999']],
2413+
labels=[[0, 1], [0, 0], [0, 1]])
2414+
2415+
Or an index with tuples with ``expand=False``:
2416+
2417+
>>> idx.str.partition(expand=False)
2418+
Index([('X', ' ', '123'), ('Y', ' ', '999')], dtype='object')
23842419
""")
23852420

23862421
@Appender(_shared_docs['str_partition'] % {

0 commit comments

Comments
 (0)