pandas.Series.mask

pandas 3.1.1 · Series and accessors · method

Replace values wherever the condition is true.

Call syntax

Series.mask(cond, other=…, *, inplace=False, axis=None, level=None)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
cond Required
Positional or keyword
bool Series/DataFrame, array-like, or callable

Provide a condition or callable producing a boolean mask.

other Optional
Positional or keyword
scalar, Series/DataFrame, or callable

Supply the second object or value used in the operation.

inplace Optional
Keyword only
Default False
bool

Choose whether to change the existing object. Where supported, an in-place call typically returns None.

axis Optional
Keyword only
Default None
int

Choose which axis the operation acts on. The accepted axis labels depend on the receiver.

level Optional
Keyword only
Default None
int

Choose an index level by name or integer position.

Returns

Series or DataFrame