Skip to content

DOC: Distinguish between different types of boolean indexing #10492 #36869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 8, 2020
16 changes: 16 additions & 0 deletions doc/source/user_guide/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,22 @@ and :ref:`Advanced Indexing <advanced>` you may select along more than one axis

df2.loc[criterion & (df2['b'] == 'x'), 'b':'c']

.. warning::

``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[sr.values, 1]`` is ok.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sr -> s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick review! I forgot to fix the doc. Done.

This type of boolean indexing is array. But ``df.iloc[sr, 1]`` would raise ``ValueError``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is array" -> "is using an array". Alternatively, "The boolean indexer is an array."
sr -> s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


.. ipython:: python

df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], list('abc'), ['A', 'B'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you specify index= and columns= here? I think it will be easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for review! That seems reasonable. Done.

sr = (df['A'] > 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like most of this doc uses s for Series. Recommend sticking with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

sr

df.loc[sr, df.columns[1]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 'B' instead of df.columns[1] would be better here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


df.iloc[sr.values, 1]

.. _indexing.basics.indexing_isin:

Indexing with isin
Expand Down