Skip to content

Where method on DataFrames can't seem to take series as conditions #9558

Closed
@max-sixty

Description

@max-sixty

I want to use where to set values across a DataFrame where a Series meets a condition.

For example:

df=pd.DataFrame({'a':[1,2,3], 'b':[4,5,6]})

But this

df.where(df['a']==2,0)

returns an unedited DataFrame.
Whereas this returns just the middle row, as you'd expect:

df[df['a']==2]

Supplying axis=0 or axis=1 doesn't help. Am I doing something wrong? Or this unintended behavior?

Versions
python: 2.7.6.final.0
pandas: 0.14.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Error ReportingIncorrect or improved errors from pandasMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions