idxmax函数方法的使用
DataFrame.idxmax(self, axis=0, skipna=True)
返回在请求轴上第一次出现最大值的索引。不包括NA/null。
参数 | 说明 |
---|---|
axis | {0或’index’,1或’columns’},默认0; |
skipna | bool, default True。排除NA / null值。如果整个行/列是NA,结果将是NA。 |
return | 沿指定轴的最大值索引。 |
考虑一个包含阿根廷食品消费的数据集。
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
'''
默认情况下,它返回每列中最大值的索引。
df.idxmax()
'''
consumption Wheat Products
co2_emissions Beef
dtype: object
'''
若要返回每行中最大值的索引,请使用axis=“columns”。
df.idxmax(axis="columns")
'''
Pork co2_emissions
Wheat Products consumption
Beef co2_emissions
dtype: object
'' '