用法:
StringMethods.partition(sep: str = ' ', expand: bool = True) → SeriesOrIndex
在第一次出現 sep 時拆分字符串。
此方法在第一次出現 sep 時拆分字符串,並返回 3 個元素,其中包含分隔符之前的部分、分隔符本身和分隔符之後的部分。如果未找到分隔符,則返回包含字符串本身的 3 個元素,後跟兩個空字符串。
- sep:str,默認“”(空格)
要拆分的字符串。
- DataFrame 或 MultiIndex
返回一個 DataFrame /MultiIndex
參數:
返回:
注意:
尚不支持參數
expand
,如果設置了默認值以外的任何值,則會引發NotImplementedError
。例子:
>>> import cudf >>> s = cudf.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-Rivers
用不同於空間的東西進行分區:
>>> s.str.partition('-') 0 1 2 0 Linda van der Berg 1 George Pitt - Rivers
也可用於索引:
>>> idx = cudf.Index(['X 123', 'Y 999']) >>> idx StringIndex(['X 123' 'Y 999'], dtype='object')
這將創建一個 MultiIndex:
>>> idx.str.partition() MultiIndex([('X', ' ', '123'), ('Y', ' ', '999')], )
相關用法
- Python cudf.core.column.string.StringMethods.pad用法及代碼示例
- Python cudf.core.column.string.StringMethods.porter_stemmer_measure用法及代碼示例
- Python cudf.core.column.string.StringMethods.is_vowel用法及代碼示例
- Python cudf.core.column.string.StringMethods.endswith用法及代碼示例
- Python cudf.core.column.string.StringMethods.title用法及代碼示例
- Python cudf.core.column.string.StringMethods.contains用法及代碼示例
- Python cudf.core.column.string.StringMethods.rsplit用法及代碼示例
- Python cudf.core.column.string.StringMethods.zfill用法及代碼示例
- Python cudf.core.column.string.StringMethods.hex_to_int用法及代碼示例
- Python cudf.core.column.string.StringMethods.htoi用法及代碼示例
- Python cudf.core.column.string.StringMethods.character_tokenize用法及代碼示例
- Python cudf.core.column.string.StringMethods.normalize_characters用法及代碼示例
- Python cudf.core.column.string.StringMethods.filter_alphanum用法及代碼示例
- Python cudf.core.column.string.StringMethods.split用法及代碼示例
- Python cudf.core.column.string.StringMethods.ngrams用法及代碼示例
- Python cudf.core.column.string.StringMethods.replace_with_backrefs用法及代碼示例
- Python cudf.core.column.string.StringMethods.insert用法及代碼示例
- Python cudf.core.column.string.StringMethods.replace用法及代碼示例
- Python cudf.core.column.string.StringMethods.rstrip用法及代碼示例
- Python cudf.core.column.string.StringMethods.replace_tokens用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cudf.core.column.string.StringMethods.partition。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。