Skip to content

Commit 1183c2e

Browse files
committed
Updated docstring
1 parent 25bf40b commit 1183c2e

File tree

1 file changed

+49
-32
lines changed

1 file changed

+49
-32
lines changed

pandas/core/strings.py

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,9 +2243,8 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
22432243
_shared_docs['str_split'] = ("""
22442244
Split strings around given separator/delimiter.
22452245
2246-
Returns a list of the words from each string in Series/Index,
2247-
split by the given delimiter string, starting at the %(side)s of the
2248-
string. Equivalent to :meth:`str.%(method)s`.
2246+
Splits the string in the Series/Index from the %(side)s,
2247+
at the specified delimiter string.Equivalent to :meth:`str.%(method)s`.
22492248
22502249
Parameters
22512250
----------
@@ -2284,31 +2283,29 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
22842283
22852284
Examples
22862285
--------
2287-
>>> s = pd.Series(["this is good text", "but this is even better"])
2286+
%(example)s
2287+
""")
22882288

2289-
By default, split and rsplit will return an object of the same size
2289+
@Appender(_shared_docs['str_split'] % {
2290+
'side':'beginning',
2291+
'method':'split',
2292+
'also': 'rsplit : Split the string at the last occurrence of delimiter',
2293+
'example':
2294+
""">>> s = pd.Series(["this is good text", "but this is even better"])
2295+
2296+
By default, split will return an object of the same size
22902297
having lists containing the split elements
22912298
22922299
>>> s.str.split()
22932300
0 [this, is, good, text]
22942301
1 [but, this, is, even, better]
2295-
dtype: object
2296-
2297-
>>> s.str.rsplit()
2298-
0 [this, is, good, text]
2299-
1 [but, this, is, even, better]
23002302
dtype: object
23012303
23022304
>>> s.str.split("random")
23032305
0 [this is good text]
23042306
1 [but this is even better]
23052307
dtype: object
23062308
2307-
>>> s.str.rsplit("random")
2308-
0 [this is good text]
2309-
1 [but this is even better]
2310-
dtype: object
2311-
23122309
When using ``expand=True``, the split and rsplit elements will
23132310
expand out into separate columns.
23142311
@@ -2331,11 +2328,6 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
23312328
1 [but th, is even better]
23322329
dtype: object
23332330
2334-
>>> s.str.rsplit("is", n=1)
2335-
0 [this , good text]
2336-
1 [but this , even better]
2337-
dtype: object
2338-
23392331
If NaN is present, it is propagated throughout the columns
23402332
during the split.
23412333
@@ -2345,23 +2337,48 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
23452337
0 1 2 3
23462338
0 this is good text
23472339
1 but this is even better
2348-
2 NaN NaN NaN NaN
2340+
2 NaN NaN NaN NaN """})
2341+
def split(self, pat=None, n=-1, expand=False):
2342+
result = str_split(self._data, pat, n=n)
2343+
return self._wrap_result(result, expand=expand)
2344+
2345+
@Appender(_shared_docs['str_split'] % {
2346+
'side':'end',
2347+
'method':'rsplit',
2348+
'also': 'split : Split the string at the first occurrence of delimiter',
2349+
'example':
2350+
""">>> s = pd.Series(["this is good text", "but this is even better"])
2351+
2352+
By default, rsplit will return an object of the same size
2353+
having lists containing the split elements
2354+
2355+
>>> s.str.rsplit()
2356+
0 [this, is, good, text]
2357+
1 [but, this, is, even, better]
2358+
dtype: object
2359+
2360+
>>> s.str.rsplit("random")
2361+
0 [this is good text]
2362+
1 [but this is even better]
2363+
dtype: object
2364+
2365+
Parameter `n` can be used to limit the number of splits in the output.
2366+
2367+
>>> s.str.rsplit("is", n=1)
2368+
0 [this , good text]
2369+
1 [but this , even better]
2370+
dtype: object
2371+
2372+
If NaN is present, it is propagated throughout the columns
2373+
during the split.
2374+
2375+
>>> s = pd.Series(["this is good text", "but this is even better", np.nan])
23492376
23502377
>>> s.str.rsplit(n=3, expand=True)
23512378
0 1 2 3
23522379
0 this is good text
23532380
1 but this is even better
2354-
2 NaN NaN NaN NaN
2355-
""")
2356-
2357-
@Appender(_shared_docs['str_split'] % dict(side='start',
2358-
method='split'))
2359-
def split(self, pat=None, n=-1, expand=False):
2360-
result = str_split(self._data, pat, n=n)
2361-
return self._wrap_result(result, expand=expand)
2362-
2363-
@Appender(_shared_docs['str_split'] % dict(side='end',
2364-
method='rsplit'))
2381+
2 NaN NaN NaN NaN """ })
23652382
def rsplit(self, pat=None, n=-1, expand=False):
23662383
result = str_rsplit(self._data, pat, n=n)
23672384
return self._wrap_result(result, expand=expand)

0 commit comments

Comments
 (0)