Skip to content

Commit 97e8775

Browse files
committed
Updated docstring for str.rsplit
1 parent 3d03fdb commit 97e8775

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

pandas/core/strings.py

+48-1
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,54 @@ def str_rsplit(arr, pat=None, n=None):
14811481
14821482
Returns
14831483
-------
1484-
split : Series/Index or DataFrame/MultiIndex of objects
1484+
Series/Index or DataFrame/MultiIndex of objects
1485+
1486+
See Also
1487+
--------
1488+
str.rsplit : Standard library version of this method.
1489+
1490+
Examples
1491+
--------
1492+
>>> s = pd.Series(["this is good text", "but this is even better"])
1493+
1494+
By default, split will return an object of the same size
1495+
having lists containing the split elements
1496+
1497+
>>> s.str.rsplit()
1498+
0 [this, is, good, text]
1499+
1 [but, this, is, even, better]
1500+
dtype: object
1501+
>>> s.str.rsplit("random")
1502+
0 [this is good text]
1503+
1 [but this is even better]
1504+
dtype: object
1505+
1506+
When using ''expand=True'', the split elements will expand out into
1507+
separate columns.
1508+
1509+
For Series object, output return type is DataFrame.
1510+
1511+
>>> s.str.rsplit(expand=True)
1512+
0 1 2 3 4
1513+
0 this is good text None
1514+
1 but this is even better
1515+
1516+
Parameter 'n' can be used to limit the number of splits in the output.
1517+
1518+
>>> s.str.rsplit("is", n=1)
1519+
0 [this , good text]
1520+
1 [but this , even better]
1521+
dtype: object
1522+
1523+
If NaN is present, it is propagated throughout the columns
1524+
during the split.
1525+
1526+
>>> s = pd.Series(["this is good text", "but this is even better", np.nan])
1527+
>>> s.str.rsplit(n=3, expand=True)
1528+
0 1 2 3
1529+
0 this is good text
1530+
1 but this is even better
1531+
2 NaN NaN NaN NaN
14851532
"""
14861533
if n is None or n == 0:
14871534
n = -1

0 commit comments

Comments
 (0)