Skip to content

DOC: Indexing and selecting data and the use of mask/where #34383

Closed
@psteinb

Description

@psteinb

Location of the documentation

https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#evaluation-order-matters

Documentation problem

The documentation talks about how not to use dfb['c'][dfb['a'].str.startswith('o')] = 42 for assignment of multiple values to a pandas.Series or pandas.DataFrame column. it does however fail to make a concrete suggestion how to do it given the example.

Suggested fix for documentation

I suggest to mention the pandas.Series.where and pandas.Series.mask methods here in order to show how the assignment can be done, i.e. by adding an example like:

dfb['c'].mask(dfb['a'].str.startswith('o'), 42)

which performs the desired assigment of rows matching o to 42. I am happy to contribute this as a PR myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsIndexingRelated 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