Skip to content

DOC: iloc boolean indexing potential wording error #47224

Open
@rhug123

Description

@rhug123

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/user_guide/indexing.html#boolean-indexing

Documentation problem

The documentation states under boolean indexing (indexing and selecting data):

"iloc supports two kinds of boolean indexing. If the indexer is a boolean Series, an error will be raised. For instance, in the following example, df.iloc[s.values, 1] is ok. The boolean indexer is an array. But df.iloc[s, 1] would raise ValueError."

The issue is with the first sentence stating that iloc supports two kinds of boolean indexing. .iloc however does not support indexing with a boolean series (only .loc does).

Suggested fix for documentation

I believe the current documentation should be replaced with the below change.

".iloc only supports one kind of boolean indexing. If the indexer is a boolean Series, an error will be raised. For instance, in the following example, df.iloc[s.values, 1] is ok. The boolean indexer is an array. But df.iloc[s, 1] would raise ValueError."

If you agree with this change, perhaps it would also be beneficial to highlight differences between loc and iloc when it comes to boolean indexing such as:

"While .loc supports two kinds of boolean indexing, .iloc only supports indexing with a boolean array. If the indexer is a boolean Series, an error will be raised. For instance, in the following example, df.iloc[s.values, 1] is ok. The boolean indexer is an array. But df.iloc[s, 1] would raise ValueError."

Metadata

Metadata

Labels

DocsIndexingRelated to indexing on series/frames, not to indexes themselves

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions