From 9530c9338919abae776d562ba46f4112129de651 Mon Sep 17 00:00:00 2001 From: Farhan Reynaldo Date: Mon, 9 Mar 2020 12:50:38 +0700 Subject: [PATCH 1/2] DOC: Fix EX01 in pandas.DataFrame.idxmax --- pandas/core/frame.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index cd5d81bc70dd9..dfe326b0f8220 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8029,6 +8029,35 @@ def idxmax(self, axis=0, skipna=True) -> Series: Notes ----- This method is the DataFrame version of ``ndarray.argmax``. + + Examples + -------- + Consider dataset containing food consumption in Argentina. + + >>> df = pd.DataFrame({'consumption': [10.51, 103.11, 55.48], + ... 'co2_emission': [37.2, 19.66, 1712]}, + ... index=['Pork', 'Wheat Products', 'Beef']) + + >>> df + consumption co2_emission + Pork 10.51 37.20 + Wheat Products 103.11 19.66 + Beef 55.48 1712.00 + + By default, it returns index for the maximum value in each columns. + + >>> df.idxmax() + consumption Wheat Products + co2_emission Beef + dtype: object + + To return index for the maximum value in each rows, use ``axis="columns"``. + + >>> df.idxmax(axis="columns") + Pork co2_emission + Wheat Products consumption + Beef co2_emission + dtype: object """ axis = self._get_axis_number(axis) indices = nanops.nanargmax(self.values, axis=axis, skipna=skipna) From 0c872b3da877157fec23ad93f0721d8c85b357b8 Mon Sep 17 00:00:00 2001 From: Farhan Reynaldo Date: Tue, 10 Mar 2020 10:58:43 +0700 Subject: [PATCH 2/2] Fix grammatical errors --- pandas/core/frame.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index dfe326b0f8220..60fc69e8222d6 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -8032,31 +8032,31 @@ def idxmax(self, axis=0, skipna=True) -> Series: Examples -------- - Consider dataset containing food consumption in Argentina. + Consider a dataset containing food consumption in Argentina. >>> df = pd.DataFrame({'consumption': [10.51, 103.11, 55.48], - ... 'co2_emission': [37.2, 19.66, 1712]}, + ... 'co2_emissions': [37.2, 19.66, 1712]}, ... index=['Pork', 'Wheat Products', 'Beef']) >>> df - consumption co2_emission + consumption co2_emissions Pork 10.51 37.20 Wheat Products 103.11 19.66 Beef 55.48 1712.00 - By default, it returns index for the maximum value in each columns. + By default, it returns the index for the maximum value in each column. >>> df.idxmax() consumption Wheat Products - co2_emission Beef + co2_emissions Beef dtype: object - To return index for the maximum value in each rows, use ``axis="columns"``. + To return the index for the maximum value in each row, use ``axis="columns"``. >>> df.idxmax(axis="columns") - Pork co2_emission + Pork co2_emissions Wheat Products consumption - Beef co2_emission + Beef co2_emissions dtype: object """ axis = self._get_axis_number(axis)