Skip to content

Commit d8d525b

Browse files
farhanreynaldoSeeminSyed
authored andcommitted
DOC: Fix EX01 in pandas.DataFrame.idxmax (pandas-dev#32551)
1 parent 389e4b9 commit d8d525b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pandas/core/frame.py

+29
Original file line numberDiff line numberDiff line change
@@ -8029,6 +8029,35 @@ def idxmax(self, axis=0, skipna=True) -> Series:
80298029
Notes
80308030
-----
80318031
This method is the DataFrame version of ``ndarray.argmax``.
8032+
8033+
Examples
8034+
--------
8035+
Consider a dataset containing food consumption in Argentina.
8036+
8037+
>>> df = pd.DataFrame({'consumption': [10.51, 103.11, 55.48],
8038+
... 'co2_emissions': [37.2, 19.66, 1712]},
8039+
... index=['Pork', 'Wheat Products', 'Beef'])
8040+
8041+
>>> df
8042+
consumption co2_emissions
8043+
Pork 10.51 37.20
8044+
Wheat Products 103.11 19.66
8045+
Beef 55.48 1712.00
8046+
8047+
By default, it returns the index for the maximum value in each column.
8048+
8049+
>>> df.idxmax()
8050+
consumption Wheat Products
8051+
co2_emissions Beef
8052+
dtype: object
8053+
8054+
To return the index for the maximum value in each row, use ``axis="columns"``.
8055+
8056+
>>> df.idxmax(axis="columns")
8057+
Pork co2_emissions
8058+
Wheat Products consumption
8059+
Beef co2_emissions
8060+
dtype: object
80328061
"""
80338062
axis = self._get_axis_number(axis)
80348063
indices = nanops.nanargmax(self.values, axis=axis, skipna=skipna)

0 commit comments

Comments
 (0)