maxframe.dataframe.DataFrame.idxmax#

DataFrame.idxmax(axis=0, skipna=True)#

返回沿指定轴第一个最大值的索引。

排除 NA/null 值。

参数:
  • axis ({0 or 'index', 1 or 'columns'}, default 0) -- 使用的轴。0 或 'index' 表示按行,1 或 'columns' 表示按列。

  • skipna (bool, default True) -- 排除 NA/null 值。如果整行/列都是 NA,则结果为 NA。

返回:

沿指定轴的最大值索引。

返回类型:

Series

抛出:

ValueError --

  • 如果行/列为空

参见

Series.idxmax

返回最大元素的索引。

备注

此方法是 ndarray.argmax 的 DataFrame 版本。

示例

考虑一个包含阿根廷食品消费的数据集。

>>> import maxframe.dataframe as md
>>> df = md.DataFrame({'consumption': [10.51, 103.11, 55.48],
...                    'co2_emissions': [37.2, 19.66, 1712]},
...                    index=['Pork', 'Wheat Products', 'Beef'])
>>> df.execute()
                consumption  co2_emissions
Pork                  10.51         37.20
Wheat Products       103.11         19.66
Beef                  55.48       1712.00

默认情况下,返回每列中最大值的索引。

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

要返回每行中最大值的索引,请使用 axis="columns"

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