cudf.core.column.string.StringMethods.filter_characters#

StringMethods.filter_characters(table: dict, keep: bool = True, repl: str | None = None) SeriesOrIndex#

Remove characters from each string using the character ranges in the given mapping table.

Parameters:
tabledict

This table is a range of Unicode ordinals to filter. The minimum value is the key and the maximum value is the value. You can use str.maketrans() as a helper function for making the filter table. Overlapping ranges will cause undefined results. Range values are inclusive.

keepboolean

If False, the character ranges in the table are removed. If True, the character ranges not in the table are removed. Default is True.

replstr

Optional replacement string to use in place of removed characters.

Returns:
Series or Index.

Examples

>>> import cudf
>>> data = ['aeiou', 'AEIOU', '0123456789']
>>> s = cudf.Series(data)
>>> s.str.filter_characters({'a':'l', 'M':'Z', '4':'6'})
0    aei
1     OU
2    456
dtype: object
>>> s.str.filter_characters({'a':'l', 'M':'Z', '4':'6'}, False, "_")
0         ___ou
1         AEI__
2    0123___789
dtype: object