cudf.Series.map#

Series.map(arg, na_action=None) cudf.core.series.Series#

Map values of Series according to input correspondence.

Used for substituting each value in a Series with another value, that may be derived from a function, a dict or a Series.

Parameters
argfunction, collections.abc.Mapping subclass or Series

Mapping correspondence.

na_action{None, ‘ignore’}, default None

If ‘ignore’, propagate NaN values, without passing them to the mapping correspondence.

Returns
Series

Same index as caller.

Notes

Please note map currently only supports fixed-width numeric type functions.

Examples

>>> s = cudf.Series(['cat', 'dog', np.nan, 'rabbit'])
>>> s
0      cat
1      dog
2     <NA>
3   rabbit
dtype: object

map accepts a dict or a Series. Values that are not found in the dict are converted to NaN, default values in dicts are currently not supported.:

>>> s.map({'cat': 'kitten', 'dog': 'puppy'})
0   kitten
1    puppy
2     <NA>
3     <NA>
dtype: object

It also accepts numeric functions:

>>> s = cudf.Series([1, 2, 3, 4, np.nan])
>>> s.map(lambda x: x ** 2)
0       1
1       4
2       9
3       16
4     <NA>
dtype: int64