用法:
StringMethods.slice_replace(start: int = None, stop: int = None, repl: str = None) → SeriesOrIndex
用新字符串替換每個字符串的指定部分。
- start:整數,可選
要替換的字符串的開始位置。默認是每個字符串的開頭。
- stop:整數,可選
要替換的字符串的結束位置。默認是每個字符串的結尾。
- repl:str,可選
要插入到指定位置值的字符串。
- str dtype 的係列/索引
將字符串的指定部分替換為
repl
字符串的新字符串。
參數:
返回:
例子:
>>> import cudf >>> s = cudf.Series(['a', 'ab', 'abc', 'abdc', 'abcde']) >>> s 0 a 1 ab 2 abc 3 abdc 4 abcde dtype: object
僅指定
start
,這意味著用repl
替換start
直到字符串的end
。>>> s.str.slice_replace(1, repl='X') 0 aX 1 aX 2 aX 3 aX 4 aX dtype: object
僅指定
stop
,這意味著將stop
的字符串的start
替換為repl
,並包括字符串的其餘部分。>>> s.str.slice_replace(stop=2, repl='X') 0 X 1 X 2 Xc 3 Xdc 4 Xcde dtype: object
指定
start
和stop
,這意味著從start
到stop
的切片將替換為repl
。start
和stop
之前或之後的所有內容都按原樣包含在內。>>> s.str.slice_replace(start=1, stop=3, repl='X') 0 aX 1 aX 2 aX 3 aXc 4 aXde dtype: object
相關用法
- Python cudf.core.column.string.StringMethods.slice_from用法及代碼示例
- Python cudf.core.column.string.StringMethods.slice用法及代碼示例
- Python cudf.core.column.string.StringMethods.split用法及代碼示例
- Python cudf.core.column.string.StringMethods.swapcase用法及代碼示例
- Python cudf.core.column.string.StringMethods.startswith用法及代碼示例
- Python cudf.core.column.string.StringMethods.strip用法及代碼示例
- 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.ngrams用法及代碼示例
- Python cudf.core.column.string.StringMethods.replace_with_backrefs用法及代碼示例
- Python cudf.core.column.string.StringMethods.insert用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cudf.core.column.string.StringMethods.slice_replace。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。