DOC: .loc doesn't document that it can take sets or dicts as arguments · Issue #42825 · pandas-dev/pandas (original) (raw)

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?