Skip to content

Documentation/behaviour error for selecting by label #7999

Closed
@ruidc

Description

@ruidc
df = pandas.DataFrame([['a'], ['b']], index=[1,2], columns=['x'])
df.loc[[3]] # does not raise KeyError as documented

"ALL of the labels for which you ask, must be in the index or a KeyError will be raised!"
http://pandas.pydata.org/pandas-docs/stable/indexing.html#selection-by-label
and
".loc is strictly label based, will raise KeyError when the items are not found":
http://pandas.pydata.org/pandas-docs/stable/indexing.html#different-choices-for-indexing-loc-iloc-and-ix

also, possibly separate bug:

df.loc[pandas.Index(['a', 'k', 'b']), : ]

DOES fail, so we have an inconsistency between .loc[values,:] and .loc[values]

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated 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