Series.str.partition()

pandas.Series.str.partition

Series.str.partition(pat=' ', expand=True)

Split the string at the first occurrence of sep, and return 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:

pat : string, default whitespace

String to split on.

expand : bool, default True

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

split : DataFrame/MultiIndex or Series/Index of objects

See also

rpartition
Split the string at the last occurrence of sep

Examples

>>> s = Series(['A_B_C', 'D_E_F', 'X'])
0    A_B_C
1    D_E_F
2        X
dtype: object
>>> s.str.partition('_')
   0  1    2
0  A  _  B_C
1  D  _  E_F
2  X
>>> s.str.rpartition('_')
     0  1  2
0  A_B  _  C
1  D_E  _  F
2          X

© 2011–2012 Lambda Foundry, Inc. and PyData Development Team
© 2008–2011 AQR Capital Management, LLC
© 2008–2014 the pandas development team
Licensed under the 3-clause BSD License.
http://pandas.pydata.org/pandas-docs/version/0.18.1/generated/pandas.Series.str.partition.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部