pandas.SparseArray.map¶
-
SparseArray.
map
(mapper)[source]¶ Map categories using input correspondence (dict, Series, or function).
Parameters: - mapper : dict, Series, callable
The correspondence from old values to new.
Returns: - SparseArray
The output array will have the same density as the input. The output fill value will be the result of applying the mapping to
self.fill_value
Examples
>>> arr = pd.SparseArray([0, 1, 2]) >>> arr.apply(lambda x: x + 10) [10, 11, 12] Fill: 10 IntIndex Indices: array([1, 2], dtype=int32)
>>> arr.apply({0: 10, 1: 11, 2: 12}) [10, 11, 12] Fill: 10 IntIndex Indices: array([1, 2], dtype=int32)
>>> arr.apply(pd.Series([10, 11, 12], index=[0, 1, 2])) [10, 11, 12] Fill: 10 IntIndex Indices: array([1, 2], dtype=int32)