From 9bffeac5dda898270880632aef3300c7b3c66f6c Mon Sep 17 00:00:00 2001 From: Farhan Reynaldo Hutabarat Date: Sat, 15 Feb 2020 18:37:42 +0700 Subject: [PATCH 1/6] DOC: Fix errors in pandas.Series.argmax --- pandas/core/base.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 56d3596f71813..69a4ecd03a2a6 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -929,11 +929,17 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs): """ Return an ndarray of the maximum argument indexer. + If multiple values equal the maximum, the first row label with that + 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 ------- @@ -942,7 +948,22 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs): See Also -------- - numpy.ndarray.argmax + numpy.ndarray.argmax : Returns the indices of the maximum values along an axis. + + Examples + -------- + >>> s = pd.Series(data=[1, None, 5, 4, 5], + ... index=['A', 'B', 'C', 'D', 'E']) + >>> s + A 1.0 + B NaN + C 5.0 + D 4.0 + E 5.0 + dtype: float64 + + >>> s.argmax() + 2 """ nv.validate_minmax_axis(axis) nv.validate_argmax_with_skipna(skipna, args, kwargs) From 9eda7cd55acaedf4822c96694fc5d5f585e813f8 Mon Sep 17 00:00:00 2001 From: Farhan Reynaldo Hutabarat Date: Tue, 18 Feb 2020 18:08:53 +0700 Subject: [PATCH 2/6] DOC: Fix errors in pandas.Series.argmax --- pandas/core/base.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 69a4ecd03a2a6..894a50d20e4f0 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -949,21 +949,26 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs): See Also -------- numpy.ndarray.argmax : Returns the indices of the maximum values along an axis. + Series.argmin : Return a ndarray of the minimum argument indexer. Examples -------- - >>> s = pd.Series(data=[1, None, 5, 4, 5], - ... index=['A', 'B', 'C', 'D', 'E']) + 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}) >>> s - A 1.0 - B NaN - C 5.0 - D 4.0 - E 5.0 + 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) From 64e814f4fc9d28d29bbe564d79400591d728ae74 Mon Sep 17 00:00:00 2001 From: Farhan Reynaldo Hutabarat Date: Tue, 18 Feb 2020 18:17:46 +0700 Subject: [PATCH 3/6] DOC: Fix errors in pandas.Series.argmax --- pandas/core/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 894a50d20e4f0..01a0e4fc2ad3e 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -948,8 +948,8 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs): See Also -------- - numpy.ndarray.argmax : Returns the indices of the maximum values along an axis. - Series.argmin : Return a ndarray of the minimum argument indexer. + numpy.ndarray.argmax : Equivalent method for numpy arrays. + Series.argmin : Similar method, but returning the minimum. Examples -------- From e44f592398e685b4dac86734131f238a11bc9958 Mon Sep 17 00:00:00 2001 From: Farhan Reynaldo Hutabarat Date: Wed, 26 Feb 2020 10:02:11 +0700 Subject: [PATCH 4/6] DOC: Fix errors in pandas.Series.argmax --- pandas/core/base.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 5de8e2b070f39..b12ddadb783d7 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -927,10 +927,10 @@ def max(self, axis=None, skipna=True, *args, **kwargs): def argmax(self, axis=None, skipna=True, *args, **kwargs): """ - Return an ndarray of the maximum argument indexer. + Return int position of the largest value in the Series". - If multiple values equal the maximum, the first row label with that - value is returned. + If the maximum is achieved in multiple locations, + the first row position is returned. Parameters ---------- @@ -943,8 +943,8 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs): Returns ------- - numpy.ndarray - Indices of the maximum values. + int + Row position of the maximum values. See Also -------- @@ -956,7 +956,7 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs): 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}) + ... 'Cinnamon Toast Crunch': 120.0, 'Cocoa Puff': 110.0}) >>> s Corn Flakes 100.0 Almond Delight 110.0 From 9d8f863315bb14b3790d2c8f8c951244a0be4cdb Mon Sep 17 00:00:00 2001 From: Farhan Reynaldo Hutabarat Date: Wed, 26 Feb 2020 10:06:16 +0700 Subject: [PATCH 5/6] DOC: Fix errors in pandas.Series.argmax --- pandas/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index b12ddadb783d7..858fac33db000 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -927,7 +927,7 @@ def max(self, axis=None, skipna=True, *args, **kwargs): def argmax(self, axis=None, skipna=True, *args, **kwargs): """ - Return int position of the largest value in the Series". + Return int position of the largest value in the Series. If the maximum is achieved in multiple locations, the first row position is returned. From 878dcc49fa28ca4950ee82e8ca900a2646a358c1 Mon Sep 17 00:00:00 2001 From: Farhan Reynaldo Hutabarat Date: Wed, 26 Feb 2020 10:11:25 +0700 Subject: [PATCH 6/6] DOC: Fix errors in pandas.Series.argmax --- pandas/core/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/base.py b/pandas/core/base.py index 858fac33db000..b9aeb32eea5c1 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -950,6 +950,8 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs): -------- numpy.ndarray.argmax : Equivalent method for numpy arrays. Series.argmin : Similar method, but returning the minimum. + Series.idxmax : Return index label of the maximum values. + Series.idxmin : Return index label of the minimum values. Examples --------