pandas.Series.str.partition
- 
Series.str.partition(sep=' ', expand=True)[source] - 
Split the string at the first occurrence of
sep.This method splits the string at the first 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 the string itself, followed by two empty strings.Parameters: - 
sep : str, default whitespace - 
String to split on.
 - 
pat : str, default whitespace - 
Deprecated since version 0.24.0: Use
sepinstead - 
expand : bool, default True - 
If True, return DataFrame/MultiIndex expanding dimensionality. If False, return Series/Index.
 
Returns: - DataFrame/MultiIndex or Series/Index of objects
 
See also
- 
 
rpartition - Split the string at the last occurrence of 
sep. - 
 
Series.str.split - Split strings around given separators.
 - 
 
str.partition - Standard library version.
 
Examples
>>> s = pd.Series(['Linda van der Berg', 'George Pitt-Rivers']) >>> s 0 Linda van der Berg 1 George Pitt-Rivers dtype: object
>>> s.str.partition() 0 1 2 0 Linda van der Berg 1 George Pitt-RiversTo partition by the last space instead of the first one:
>>> s.str.rpartition() 0 1 2 0 Linda van der Berg 1 George Pitt-RiversTo partition by something different than a space:
>>> s.str.partition('-') 0 1 2 0 Linda van der Berg 1 George Pitt - RiversTo return a Series containining tuples instead of a DataFrame:
>>> s.str.partition('-', expand=False) 0 (Linda van der Berg, , ) 1 (George Pitt, -, Rivers) dtype: objectAlso 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']], codes=[[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') - 
 
    © 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
    https://pandas.pydata.org/pandas-docs/version/0.24.2/reference/api/pandas.Series.str.partition.html