Skip to content

DOC: move idxmin and idxmax docs from core/shared_docs.py to core/frame.py #59735

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 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 142 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -12745,10 +12745,80 @@ def nunique(self, axis: Axis = 0, dropna: bool = True) -> Series:
"""
return self.apply(Series.nunique, axis=axis, dropna=dropna)

@doc(_shared_docs["idxmin"], numeric_only_default="False")
def idxmin(
self, axis: Axis = 0, skipna: bool = True, numeric_only: bool = False
) -> Series:
"""
Return index of first occurrence of minimum over requested axis.

NA/null values are excluded.

Parameters
----------
axis : {{0 or 'index', 1 or 'columns'}}, default 0
The axis to use. 0 or 'index' for row-wise, 1 or 'columns' for column-wise.
skipna : bool, default True
Exclude NA/null values. If the entire DataFrame is NA,
or if ``skipna=False`` and there is an NA value, this method
will raise a ``ValueError``.
numeric_only : bool, default False
Include only `float`, `int` or `boolean` data.

.. versionadded:: 1.5.0

Returns
-------
Series
Indexes of minima along the specified axis.

Raises
------
ValueError
* If the row/column is empty

See Also
--------
Series.idxmin : Return index of the minimum element.

Notes
-----
This method is the DataFrame version of ``ndarray.argmin``.

Examples
--------
Consider a dataset containing food consumption in Argentina.

>>> df = pd.DataFrame(
... {
... {
... "consumption": [10.51, 103.11, 55.48],
... "co2_emissions": [37.2, 19.66, 1712],
... }
... },
... index=["Pork", "Wheat Products", "Beef"],
... )

>>> df
consumption co2_emissions
Pork 10.51 37.20
Wheat Products 103.11 19.66
Beef 55.48 1712.00

By default, it returns the index for the minimum value in each column.

>>> df.idxmin()
consumption Pork
co2_emissions Wheat Products
dtype: object

To return the index for the minimum value in each row, use ``axis="columns"``.

>>> df.idxmin(axis="columns")
Pork consumption
Wheat Products co2_emissions
Beef consumption
dtype: object
"""
axis = self._get_axis_number(axis)

if self.empty and len(self.axes[axis]):
Expand Down Expand Up @@ -12782,10 +12852,80 @@ def idxmin(
final_result = data._constructor_sliced(result, index=data._get_agg_axis(axis))
return final_result.__finalize__(self, method="idxmin")

@doc(_shared_docs["idxmax"], numeric_only_default="False")
def idxmax(
self, axis: Axis = 0, skipna: bool = True, numeric_only: bool = False
) -> Series:
"""
Return index of first occurrence of maximum over requested axis.

NA/null values are excluded.

Parameters
----------
axis : {{0 or 'index', 1 or 'columns'}}, default 0
The axis to use. 0 or 'index' for row-wise, 1 or 'columns' for column-wise.
skipna : bool, default True
Exclude NA/null values. If the entire DataFrame is NA,
or if ``skipna=False`` and there is an NA value, this method
will raise a ``ValueError``.
numeric_only : bool, default False
Include only `float`, `int` or `boolean` data.

.. versionadded:: 1.5.0

Returns
-------
Series
Indexes of maxima along the specified axis.

Raises
------
ValueError
* If the row/column is empty

See Also
--------
Series.idxmax : Return index of the maximum element.

Notes
-----
This method is the DataFrame version of ``ndarray.argmax``.

Examples
--------
Consider a dataset containing food consumption in Argentina.

>>> df = pd.DataFrame(
... {
... {
... "consumption": [10.51, 103.11, 55.48],
... "co2_emissions": [37.2, 19.66, 1712],
... }
... },
... index=["Pork", "Wheat Products", "Beef"],
... )

>>> df
consumption co2_emissions
Pork 10.51 37.20
Wheat Products 103.11 19.66
Beef 55.48 1712.00

By default, it returns the index for the maximum value in each column.

>>> df.idxmax()
consumption Wheat Products
co2_emissions Beef
dtype: object

To return the index for the maximum value in each row, use ``axis="columns"``.

>>> df.idxmax(axis="columns")
Pork co2_emissions
Wheat Products consumption
Beef co2_emissions
dtype: object
"""
axis = self._get_axis_number(axis)

if self.empty and len(self.axes[axis]):
Expand Down
130 changes: 0 additions & 130 deletions pandas/core/shared_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,133 +649,3 @@
3 3 d e
4 4 e e
"""

_shared_docs["idxmin"] = """
Return index of first occurrence of minimum over requested axis.

NA/null values are excluded.

Parameters
----------
axis : {{0 or 'index', 1 or 'columns'}}, default 0
The axis to use. 0 or 'index' for row-wise, 1 or 'columns' for column-wise.
skipna : bool, default True
Exclude NA/null values. If the entire Series is NA, or if ``skipna=False``
and there is an NA value, this method will raise a ``ValueError``.
numeric_only : bool, default {numeric_only_default}
Include only `float`, `int` or `boolean` data.

.. versionadded:: 1.5.0

Returns
-------
Series
Indexes of minima along the specified axis.

Raises
------
ValueError
* If the row/column is empty

See Also
--------
Series.idxmin : Return index of the minimum element.

Notes
-----
This method is the DataFrame version of ``ndarray.argmin``.

Examples
--------
Consider a dataset containing food consumption in Argentina.

>>> df = pd.DataFrame({{'consumption': [10.51, 103.11, 55.48],
... 'co2_emissions': [37.2, 19.66, 1712]}},
... index=['Pork', 'Wheat Products', 'Beef'])

>>> df
consumption co2_emissions
Pork 10.51 37.20
Wheat Products 103.11 19.66
Beef 55.48 1712.00

By default, it returns the index for the minimum value in each column.

>>> df.idxmin()
consumption Pork
co2_emissions Wheat Products
dtype: object

To return the index for the minimum value in each row, use ``axis="columns"``.

>>> df.idxmin(axis="columns")
Pork consumption
Wheat Products co2_emissions
Beef consumption
dtype: object
"""

_shared_docs["idxmax"] = """
Return index of first occurrence of maximum over requested axis.

NA/null values are excluded.

Parameters
----------
axis : {{0 or 'index', 1 or 'columns'}}, default 0
The axis to use. 0 or 'index' for row-wise, 1 or 'columns' for column-wise.
skipna : bool, default True
Exclude NA/null values. If the entire Series is NA, or if ``skipna=False``
and there is an NA value, this method will raise a ``ValueError``.
numeric_only : bool, default {numeric_only_default}
Include only `float`, `int` or `boolean` data.

.. versionadded:: 1.5.0

Returns
-------
Series
Indexes of maxima along the specified axis.

Raises
------
ValueError
* If the row/column is empty

See Also
--------
Series.idxmax : Return index of the maximum element.

Notes
-----
This method is the DataFrame version of ``ndarray.argmax``.

Examples
--------
Consider a dataset containing food consumption in Argentina.

>>> df = pd.DataFrame({{'consumption': [10.51, 103.11, 55.48],
... 'co2_emissions': [37.2, 19.66, 1712]}},
... index=['Pork', 'Wheat Products', 'Beef'])

>>> df
consumption co2_emissions
Pork 10.51 37.20
Wheat Products 103.11 19.66
Beef 55.48 1712.00

By default, it returns the index for the maximum value in each column.

>>> df.idxmax()
consumption Wheat Products
co2_emissions Beef
dtype: object

To return the index for the maximum value in each row, use ``axis="columns"``.

>>> df.idxmax(axis="columns")
Pork co2_emissions
Wheat Products consumption
Beef co2_emissions
dtype: object
"""
Loading