- StringMethods.replace_tokens(targets, replacements, delimiter: Optional[str] = None) SeriesOrIndex #
The targets tokens are searched for within each string in the series and replaced with the corresponding replacements if found. Tokens are identified by the delimiter character provided.
- targetsarray-like, Sequence or Series
The tokens to search for inside each string.
- replacementsarray-like, Sequence, Series or str
The strings to replace for each found target token found. Alternately, this can be a single str instance and would be used as replacement for each string found.
The character used to locate the tokens of each string. Default is whitespace.
- Series or Index of object.
>>> import cudf >>> sr = cudf.Series(["this is me", "theme music", ""]) >>> targets = cudf.Series(["is", "me"]) >>> sr.str.replace_tokens(targets=targets, replacements="_") 0 this _ _ 1 theme music 2 dtype: object >>> sr = cudf.Series(["this;is;me", "theme;music", ""]) >>> sr.str.replace_tokens(targets=targets, replacements=":") 0 this;is;me 1 theme;music 2 dtype: object