Pandas functions
Pandas Where β pd.DataFrame.where()
Pandas where to replace values based on condition
Pandas Where will replace values where your condition is False
. It is useful when you have values that do not meet a criteria, and they need replacing.
We donβt often use this function, but it can be a handy one liner instead of iterating through a DataFrame or Series with.apply()
Pseudo code: Where a condition is false, replace a value.
Pandas Where
Where
.where()
has two main parameters, cond
and other
. Both of these are flexible to take Series, DataFrame or callable.
- cond: Which stands for condition. This can either be a Series, DataFrame, or callable (function). WHERE this condition is
false
, pandas will replace values. I know, itβs a bit counter intuitive. - Other What to replace your values with. This again can be a scalar (single value), Series, DataFrame, or callable.
- Other Parameters: To check out the other parameters that are not used that often, see the official documentation.
Letβs run through each iteration of the above parameters