pandas.DataFrame.where
pandas 3.1.1 · DataFrame · method
Keep values where a condition is true and replace the rest with the supplied alternative.
Call syntax
DataFrame.where(cond, other=…, *, inplace=False, axis=None, level=None)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted 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, array-like, Series/DataFrame, Index, 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