Skip to content

DOC: Distinguish between different types of boolean indexing #10492

Closed
@jcjf

Description

@jcjf

It's not clear from the docs that indexing with a boolean ndarray isn't the same as indexing with a boolean Series. It took me a while to realise that:

import pandas as pd
df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], list('abc'), ['one', 'two'])
sr = (df['one'] > 2)
df.loc[sr, 'two']      # This is ok
df.iloc[sr, 1]         # But this is not
df.iloc[sr.values, 1]  # The right way to use iloc

I've since read through #3631 and it makes sense to me. However, even though the docs emphasise that .iloc is purely integer-based, it didn't click at the time that indexability of Series was the problem I was facing.

Metadata

Metadata

Assignees

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