Skip to content

DOC: .loc doesn't document that it can take sets or dicts as arguments #42825

Closed
@Dr-Irv

Description

@Dr-Irv

Location of the documentation

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.loc.html?highlight=loc#pandas.DataFrame.loc

Documentation problem

Surprisingly, the following code works:

import pandas as pd

df = pd.DataFrame([["a", 1], ["b", 2], ["c", 3]], columns=["let", "num"]).set_index(
    "let"
)

dfl = df.loc[set(["a", "b"]), :]

print(dfl)

dd = {"a": 10, "c": 12}

dfd = df.loc[dd, "num"]

print(dfd)

In the documentation, we don't say that you can pass a set or a dict as one of the arguments to .loc .

So either we update the documentation, or maybe we should be raising an Exception?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeprecateFunctionality to remove in pandasDocsIndexingRelated 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