用法:
StringMethods.replace(pat: Union[str, Sequence], repl: Union[str, Sequence], n: int = - 1, case=None, flags: int = 0, regex: bool = True) → SeriesOrIndex
用其他字符串替換係列/索引中出現的模式/正則表達式。等效於 str.replace() 或 re.sub() 。
- pat:str 或 list-like
要替換為字符序列或正則表達式的字符串。
- repl:str 或 list-like
用作替換的字符串。
- n:int,默認 -1(全部)
從一開始就進行的更換次數。
- regex:布爾值,默認為真
如果為 True,則假定模式是正則表達式。如果為 False,則將模式視為文字字符串。
- str dtype 的係列/索引
將所有匹配的 pat 替換為 repl 的對象的副本。
參數:
返回:
注意:
參數
case
和flags
尚不受支持,如果設置了默認值以外的任何值,則會引發NotImplementedError
。例子:
>>> import cudf >>> s = cudf.Series(['foo', 'fuz', None]) >>> s 0 foo 1 fuz 2 <NA> dtype: object
當 pat 是一個字符串並且 regex 為 True(默認值)時,給定的 pat 被編譯為一個正則表達式。當 repl 是一個字符串時,它會像
re.sub()
一樣替換匹配的正則表達式模式。係列中的 NaN 值保持原樣:>>> s.str.replace('f.', 'ba', regex=True) 0 bao 1 baz 2 <NA> dtype: object
當 pat 是一個字符串並且
regex
為 False 時,每個 pat 都被替換為 repl,就像str.replace()
一樣:>>> s.str.replace('f.', 'ba', regex=False) 0 foo 1 fuz 2 <NA> dtype: object
相關用法
- Python cudf.core.column.string.StringMethods.replace_with_backrefs用法及代碼示例
- Python cudf.core.column.string.StringMethods.replace_tokens用法及代碼示例
- Python cudf.core.column.string.StringMethods.repeat用法及代碼示例
- Python cudf.core.column.string.StringMethods.rsplit用法及代碼示例
- Python cudf.core.column.string.StringMethods.rstrip用法及代碼示例
- Python cudf.core.column.string.StringMethods.rfind用法及代碼示例
- Python cudf.core.column.string.StringMethods.rindex用法及代碼示例
- Python cudf.core.column.string.StringMethods.rpartition用法及代碼示例
- Python cudf.core.column.string.StringMethods.rjust用法及代碼示例
- 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.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用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cudf.core.column.string.StringMethods.replace。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。