Skip to content
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: Fix errors in pandas.Series.argmax #32019

Merged
merged 9 commits into from
Feb 26, 2020
28 changes: 27 additions & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,11 +929,17 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs):
"""
Return an ndarray of the maximum argument indexer.
Copy link
Member

Choose a reason for hiding this comment

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

is this sentence accurate? it looks like we return an int, not ndarray

Copy link
Member

Choose a reason for hiding this comment

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

(also relevant for the Returns section)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think this okay?

Return row position of the maximum argument indexer.

And also change for the Returns section:

Returns
-------
int
    row position of the maximum values.

Copy link
Member

Choose a reason for hiding this comment

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

"maximum argument indexer" is awkward. how about "Returns int position of the largest value in the Series"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"maximum argument indexer" is awkward. how about "Returns int position of the largest value in the Series"

I think this one is easier to understand.


If multiple values equal the maximum, the first row label with that
Copy link
Member

Choose a reason for hiding this comment

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

If the maximum is achieved in multiple locations, the first such location is returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think we should go with location instead of row position?

Copy link
Member

Choose a reason for hiding this comment

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

"row position" sounds good. Definitely not "row label".

value is returned.

Parameters
----------
axis : {None}
Dummy argument for consistency with Series.
skipna : bool, default True
Exclude NA/null values when showing the result.
*args, **kwargs
Additional arguments and keywords for compatibility with NumPy.

Returns
-------
Expand All @@ -942,7 +948,27 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs):

See Also
--------
numpy.ndarray.argmax
numpy.ndarray.argmax : Equivalent method for numpy arrays.
Series.argmin : Similar method, but returning the minimum.
Copy link
Member

Choose a reason for hiding this comment

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

Series.idxmax, Series.idxmin might also make sense here


Examples
--------
Consider dataset containing cereal calories

>>> s = pd.Series({'Corn Flakes': 100.0, 'Almond Delight': 110.0,
... 'Cinnamon Toast Crunch': 120.0, 'Cocoa Puff': 110.0})
Copy link
Member

Choose a reason for hiding this comment

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

@datapythonista do we care about getting an extra space before the quote 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.

Is this what you're looking for?

>>> s = pd.Series({'Corn Flakes' : 100.0, 'Almond Delight' : 110.0,
...               'Cinnamon Toast Crunch' : 120.0, 'Cocoa Puff' : 110.0})

Copy link
Member

Choose a reason for hiding this comment

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

i meant an extra space after the ... on the second line, so that the single-quote in Cinnamon Toast Crunch aligned with the single-quote in Corn Flakes. Feel free to ignore, unless @datapythonista chimes in on the policy

>>> s
Corn Flakes 100.0
Almond Delight 110.0
Cinnamon Toast Crunch 120.0
Cocoa Puff 110.0
dtype: float64

>>> s.argmax()
2

The maximum cereal calories is in the third element,
since series is zero-indexed.
"""
nv.validate_minmax_axis(axis)
nv.validate_argmax_with_skipna(skipna, args, kwargs)
Expand Down