Allow .where to accept callable as condition · Issue #12533 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
Allow .where
and .mask
to accept callable
as cond. This is useful if DataFrame
is changed during method chaining.
df = pd.DataFrame(np.random.randn(2, 2))
df.where(lambda x: x > 0)
# currently raises ValueError
Expected Output
Should be the same as:
df.where(df > 0)
# 0 1
#0 0.689202 NaN
#1 NaN 0.261644