pandas 1.4.2

ParametersReturnsBackRef
rpartition(self, sep=' ', expand=True)

This method splits the string at the last occurrence of sep , 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 3 elements containing two empty strings, followed by the string itself.

Parameters

sep : str, default whitespace

String to split on.

expand : bool, default True

If True, return DataFrame/MultiIndex expanding dimensionality. If False, return Series/Index.

Returns

DataFrame/MultiIndex or Series/Index of objects

Split the string at the last occurrence of sep .

See Also

Series.str.split

Split strings around given separators.

partition

Split the string at the first occurrence of :None:None:`sep`.

str.partition

Standard library version.

Examples

This example is valid syntax, but we were not able to check execution
>>> s = pd.Series(['Linda van der Berg', 'George Pitt-Rivers'])
... s 0 Linda van der Berg 1 George Pitt-Rivers dtype: object
This example is valid syntax, but we were not able to check execution
>>> 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:

This example is valid syntax, but we were not able to check execution
>>> s.str.rpartition()
               0  1            2
0  Linda van der            Berg
1         George     Pitt-Rivers

To partition by something different than a space:

This example is valid syntax, but we were not able to check execution
>>> s.str.partition('-')
                    0  1       2
0  Linda van der Berg
1         George Pitt  -  Rivers

To return a Series containing tuples instead of a DataFrame:

This example is valid syntax, but we were not able to check execution
>>> s.str.partition('-', expand=False)
0    (Linda van der Berg, , )
1    (George Pitt, -, Rivers)
dtype: object

Also available on indices:

This example is valid syntax, but we were not able to check execution
>>> idx = pd.Index(['X 123', 'Y 999'])
... idx Index(['X 123', 'Y 999'], dtype='object')

Which will create a MultiIndex:

This example is valid syntax, but we were not able to check execution
>>> idx.str.partition()
MultiIndex([('X', ' ', '123'),
            ('Y', ' ', '999')],
           )

Or an index with tuples with expand=False :

This example is valid syntax, but we were not able to check execution
>>> idx.str.partition(expand=False)
Index([('X', ' ', '123'), ('Y', ' ', '999')], dtype='object')
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.strings.accessor.StringMethods.partition

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/strings/accessor.py#955
type: <class 'function'>
Commit: