-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
DOC: Distinguish between different types of boolean indexing #10492 #36869
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @junjunjunk for the PR!
Some stylistic comments.
I also think it might be good to place this in a warning box following the discussion of boolean indexing with iloc
doc/source/user_guide/indexing.rst
Outdated
@@ -933,6 +933,20 @@ and :ref:`Advanced Indexing <advanced>` you may select along more than one axis | |||
|
|||
df2.loc[criterion & (df2['b'] == 'x'), 'b':'c'] | |||
|
|||
``iloc`` distinguishes between different types of boolean indexing. If the type of boolean indexing is ``Series``, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iloc
supports two kinds of boolean indexing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the indexer is a boolean Series
, ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
doc/source/user_guide/indexing.rst
Outdated
@@ -933,6 +933,20 @@ and :ref:`Advanced Indexing <advanced>` you may select along more than one axis | |||
|
|||
df2.loc[criterion & (df2['b'] == 'x'), 'b':'c'] | |||
|
|||
``iloc`` distinguishes between different types of boolean indexing. If the type of boolean indexing is ``Series``, | |||
an error will be raised. For instance, in the following example, ``df.iloc[sr.values, 1]`` is ok. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what type of error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see below it's a ValueError, just say that here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also you need two backticks around ValueError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
doc/source/user_guide/indexing.rst
Outdated
|
||
.. ipython:: python | ||
|
||
df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], list('abc'), ['column_1', 'column_2']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make the column names 'A'
, 'B'
(to make this look a bit cleaner)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Thanks @arw2019 . |
doc/source/user_guide/indexing.rst
Outdated
|
||
.. ipython:: python | ||
|
||
df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], list('abc'), ['A', 'B']) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
doc/source/user_guide/indexing.rst
Outdated
.. ipython:: python | ||
|
||
df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], list('abc'), ['A', 'B']) | ||
sr = (df['A'] > 2) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
doc/source/user_guide/indexing.rst
Outdated
sr = (df['A'] > 2) | ||
sr | ||
|
||
df.loc[sr, df.columns[1]] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, two more comments.
doc/source/user_guide/indexing.rst
Outdated
.. 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sr -> s
There was a problem hiding this comment.
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.
doc/source/user_guide/indexing.rst
Outdated
|
||
``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. | ||
This type of boolean indexing is array. But ``df.iloc[sr, 1]`` would raise ``ValueError``. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
would love to get a hacktoberfest tag if possible. #36837 |
thanks @junjunjunk |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff