Skip to content

Commit 5a3a4f3

Browse files
authored
DOC: move idxmin and idxmax docs from core/shared_docs.py to core/frame.py (#59735)
move idxmin, idxmax docstring from shared_docs.py to frame.py
1 parent 4a16b44 commit 5a3a4f3

File tree

2 files changed

+142
-132
lines changed

2 files changed

+142
-132
lines changed

pandas/core/frame.py

+142-2
Original file line numberDiff line numberDiff line change
@@ -12745,10 +12745,80 @@ def nunique(self, axis: Axis = 0, dropna: bool = True) -> Series:
1274512745
"""
1274612746
return self.apply(Series.nunique, axis=axis, dropna=dropna)
1274712747

12748-
@doc(_shared_docs["idxmin"], numeric_only_default="False")
1274912748
def idxmin(
1275012749
self, axis: Axis = 0, skipna: bool = True, numeric_only: bool = False
1275112750
) -> Series:
12751+
"""
12752+
Return index of first occurrence of minimum over requested axis.
12753+
12754+
NA/null values are excluded.
12755+
12756+
Parameters
12757+
----------
12758+
axis : {{0 or 'index', 1 or 'columns'}}, default 0
12759+
The axis to use. 0 or 'index' for row-wise, 1 or 'columns' for column-wise.
12760+
skipna : bool, default True
12761+
Exclude NA/null values. If the entire DataFrame is NA,
12762+
or if ``skipna=False`` and there is an NA value, this method
12763+
will raise a ``ValueError``.
12764+
numeric_only : bool, default False
12765+
Include only `float`, `int` or `boolean` data.
12766+
12767+
.. versionadded:: 1.5.0
12768+
12769+
Returns
12770+
-------
12771+
Series
12772+
Indexes of minima along the specified axis.
12773+
12774+
Raises
12775+
------
12776+
ValueError
12777+
* If the row/column is empty
12778+
12779+
See Also
12780+
--------
12781+
Series.idxmin : Return index of the minimum element.
12782+
12783+
Notes
12784+
-----
12785+
This method is the DataFrame version of ``ndarray.argmin``.
12786+
12787+
Examples
12788+
--------
12789+
Consider a dataset containing food consumption in Argentina.
12790+
12791+
>>> df = pd.DataFrame(
12792+
... {
12793+
... {
12794+
... "consumption": [10.51, 103.11, 55.48],
12795+
... "co2_emissions": [37.2, 19.66, 1712],
12796+
... }
12797+
... },
12798+
... index=["Pork", "Wheat Products", "Beef"],
12799+
... )
12800+
12801+
>>> df
12802+
consumption co2_emissions
12803+
Pork 10.51 37.20
12804+
Wheat Products 103.11 19.66
12805+
Beef 55.48 1712.00
12806+
12807+
By default, it returns the index for the minimum value in each column.
12808+
12809+
>>> df.idxmin()
12810+
consumption Pork
12811+
co2_emissions Wheat Products
12812+
dtype: object
12813+
12814+
To return the index for the minimum value in each row, use ``axis="columns"``.
12815+
12816+
>>> df.idxmin(axis="columns")
12817+
Pork consumption
12818+
Wheat Products co2_emissions
12819+
Beef consumption
12820+
dtype: object
12821+
"""
1275212822
axis = self._get_axis_number(axis)
1275312823

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

12785-
@doc(_shared_docs["idxmax"], numeric_only_default="False")
1278612855
def idxmax(
1278712856
self, axis: Axis = 0, skipna: bool = True, numeric_only: bool = False
1278812857
) -> Series:
12858+
"""
12859+
Return index of first occurrence of maximum over requested axis.
12860+
12861+
NA/null values are excluded.
12862+
12863+
Parameters
12864+
----------
12865+
axis : {{0 or 'index', 1 or 'columns'}}, default 0
12866+
The axis to use. 0 or 'index' for row-wise, 1 or 'columns' for column-wise.
12867+
skipna : bool, default True
12868+
Exclude NA/null values. If the entire DataFrame is NA,
12869+
or if ``skipna=False`` and there is an NA value, this method
12870+
will raise a ``ValueError``.
12871+
numeric_only : bool, default False
12872+
Include only `float`, `int` or `boolean` data.
12873+
12874+
.. versionadded:: 1.5.0
12875+
12876+
Returns
12877+
-------
12878+
Series
12879+
Indexes of maxima along the specified axis.
12880+
12881+
Raises
12882+
------
12883+
ValueError
12884+
* If the row/column is empty
12885+
12886+
See Also
12887+
--------
12888+
Series.idxmax : Return index of the maximum element.
12889+
12890+
Notes
12891+
-----
12892+
This method is the DataFrame version of ``ndarray.argmax``.
12893+
12894+
Examples
12895+
--------
12896+
Consider a dataset containing food consumption in Argentina.
12897+
12898+
>>> df = pd.DataFrame(
12899+
... {
12900+
... {
12901+
... "consumption": [10.51, 103.11, 55.48],
12902+
... "co2_emissions": [37.2, 19.66, 1712],
12903+
... }
12904+
... },
12905+
... index=["Pork", "Wheat Products", "Beef"],
12906+
... )
12907+
12908+
>>> df
12909+
consumption co2_emissions
12910+
Pork 10.51 37.20
12911+
Wheat Products 103.11 19.66
12912+
Beef 55.48 1712.00
12913+
12914+
By default, it returns the index for the maximum value in each column.
12915+
12916+
>>> df.idxmax()
12917+
consumption Wheat Products
12918+
co2_emissions Beef
12919+
dtype: object
12920+
12921+
To return the index for the maximum value in each row, use ``axis="columns"``.
12922+
12923+
>>> df.idxmax(axis="columns")
12924+
Pork co2_emissions
12925+
Wheat Products consumption
12926+
Beef co2_emissions
12927+
dtype: object
12928+
"""
1278912929
axis = self._get_axis_number(axis)
1279012930

1279112931
if self.empty and len(self.axes[axis]):

pandas/core/shared_docs.py

-130
Original file line numberDiff line numberDiff line change
@@ -649,133 +649,3 @@
649649
3 3 d e
650650
4 4 e e
651651
"""
652-
653-
_shared_docs["idxmin"] = """
654-
Return index of first occurrence of minimum over requested axis.
655-
656-
NA/null values are excluded.
657-
658-
Parameters
659-
----------
660-
axis : {{0 or 'index', 1 or 'columns'}}, default 0
661-
The axis to use. 0 or 'index' for row-wise, 1 or 'columns' for column-wise.
662-
skipna : bool, default True
663-
Exclude NA/null values. If the entire Series is NA, or if ``skipna=False``
664-
and there is an NA value, this method will raise a ``ValueError``.
665-
numeric_only : bool, default {numeric_only_default}
666-
Include only `float`, `int` or `boolean` data.
667-
668-
.. versionadded:: 1.5.0
669-
670-
Returns
671-
-------
672-
Series
673-
Indexes of minima along the specified axis.
674-
675-
Raises
676-
------
677-
ValueError
678-
* If the row/column is empty
679-
680-
See Also
681-
--------
682-
Series.idxmin : Return index of the minimum element.
683-
684-
Notes
685-
-----
686-
This method is the DataFrame version of ``ndarray.argmin``.
687-
688-
Examples
689-
--------
690-
Consider a dataset containing food consumption in Argentina.
691-
692-
>>> df = pd.DataFrame({{'consumption': [10.51, 103.11, 55.48],
693-
... 'co2_emissions': [37.2, 19.66, 1712]}},
694-
... index=['Pork', 'Wheat Products', 'Beef'])
695-
696-
>>> df
697-
consumption co2_emissions
698-
Pork 10.51 37.20
699-
Wheat Products 103.11 19.66
700-
Beef 55.48 1712.00
701-
702-
By default, it returns the index for the minimum value in each column.
703-
704-
>>> df.idxmin()
705-
consumption Pork
706-
co2_emissions Wheat Products
707-
dtype: object
708-
709-
To return the index for the minimum value in each row, use ``axis="columns"``.
710-
711-
>>> df.idxmin(axis="columns")
712-
Pork consumption
713-
Wheat Products co2_emissions
714-
Beef consumption
715-
dtype: object
716-
"""
717-
718-
_shared_docs["idxmax"] = """
719-
Return index of first occurrence of maximum over requested axis.
720-
721-
NA/null values are excluded.
722-
723-
Parameters
724-
----------
725-
axis : {{0 or 'index', 1 or 'columns'}}, default 0
726-
The axis to use. 0 or 'index' for row-wise, 1 or 'columns' for column-wise.
727-
skipna : bool, default True
728-
Exclude NA/null values. If the entire Series is NA, or if ``skipna=False``
729-
and there is an NA value, this method will raise a ``ValueError``.
730-
numeric_only : bool, default {numeric_only_default}
731-
Include only `float`, `int` or `boolean` data.
732-
733-
.. versionadded:: 1.5.0
734-
735-
Returns
736-
-------
737-
Series
738-
Indexes of maxima along the specified axis.
739-
740-
Raises
741-
------
742-
ValueError
743-
* If the row/column is empty
744-
745-
See Also
746-
--------
747-
Series.idxmax : Return index of the maximum element.
748-
749-
Notes
750-
-----
751-
This method is the DataFrame version of ``ndarray.argmax``.
752-
753-
Examples
754-
--------
755-
Consider a dataset containing food consumption in Argentina.
756-
757-
>>> df = pd.DataFrame({{'consumption': [10.51, 103.11, 55.48],
758-
... 'co2_emissions': [37.2, 19.66, 1712]}},
759-
... index=['Pork', 'Wheat Products', 'Beef'])
760-
761-
>>> df
762-
consumption co2_emissions
763-
Pork 10.51 37.20
764-
Wheat Products 103.11 19.66
765-
Beef 55.48 1712.00
766-
767-
By default, it returns the index for the maximum value in each column.
768-
769-
>>> df.idxmax()
770-
consumption Wheat Products
771-
co2_emissions Beef
772-
dtype: object
773-
774-
To return the index for the maximum value in each row, use ``axis="columns"``.
775-
776-
>>> df.idxmax(axis="columns")
777-
Pork co2_emissions
778-
Wheat Products consumption
779-
Beef co2_emissions
780-
dtype: object
781-
"""

0 commit comments

Comments
 (0)