dask.dataframe.Series.map¶
- Series.map(arg, na_action=None, meta=<no_default>)[source]¶
Map values of Series according to an input mapping or function.
This docstring was copied from pandas.core.series.Series.map.
Some inconsistencies with the Dask version may exist.
Used for substituting each value in a Series with another value, that may be derived from a function, a
dictor aSeries.- 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.
- metapd.DataFrame, pd.Series, dict, iterable, tuple, optional
An empty
pd.DataFrameorpd.Seriesthat matches the dtypes and column names of the output. This metadata is necessary for many algorithms in dask dataframe to work. For ease of use, some alternative inputs are also available. Instead of aDataFrame, adictof{name: dtype}or iterable of(name, dtype)can be provided (note that the order of the names should match the order of the columns). Instead of a series, a tuple of(name, dtype)can be used. If not provided, dask will try to infer the metadata. This may lead to unexpected results, so providingmetais recommended. For more information, seedask.dataframe.utils.make_meta.
- Returns:
- Series
Same index as caller.
See also
Series.applyFor applying more complex functions on a Series.
Series.replaceReplace values given in to_replace with value.
DataFrame.applyApply a function row-/column-wise.
DataFrame.mapApply a function elementwise on a whole DataFrame.
Notes
When
argis a dictionary, values in Series that are not in the dictionary (as keys) are converted toNaN. However, if the dictionary is adictsubclass that defines__missing__(i.e. provides a method for default values), then this default is used rather thanNaN.Examples
>>> s = pd.Series(['cat', 'dog', np.nan, 'rabbit']) >>> s 0 cat 1 dog 2 NaN 3 rabbit dtype: object
mapaccepts adictor aSeries. Values that are not found in thedictare converted toNaN, unless the dict has a default value (e.g.defaultdict):>>> s.map({'cat': 'kitten', 'dog': 'puppy'}) 0 kitten 1 puppy 2 NaN 3 NaN dtype: object
It also accepts a function:
>>> s.map('I am a {}'.format) 0 I am a cat 1 I am a dog 2 I am a nan 3 I am a rabbit dtype: object
To avoid applying the function to missing values (and keep them as
NaN)na_action='ignore'can be used:>>> s.map('I am a {}'.format, na_action='ignore') 0 I am a cat 1 I am a dog 2 NaN 3 I am a rabbit dtype: object