Skip to content

Allow .where to accept callable as condition #12533

Closed
@sinhrks

Description

@sinhrks

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions