DataFrame.idxmax(self, axis=0, skipna=True) [source]
返回在请求轴上第一次出现最大值的索引。不包括NA/null。
参数:axis : {0或'index',1或'columns'},默认0
行为0或'index',列为1或'columns'
skipna : boolean,默认为True
排除NA/null。如果整个行/列均为NA,则结果为NA。
返回值:Series
沿指定轴的最大值索引。
Raises:ValueError
如果行/列为空
Notes
此方法是的DataFrame版本ndarray.argmax。
例子
使用idxmax()函数来沿索引轴查找最大值的索引# importing pandas as pd
import pandas as pd
# Creating the dataframe
df = pd.DataFrame({"A":[4, 5, 2, 6],
"B":[11, 2, 5, 8],
"C":[1, 8, 66, 4]})
# Print the dataframe
df
输出:A B C
0 4 11 1
1 5 2 8
2 2 5 66
3 6 8 4
idxmax()沿索引轴应用# applying idxmax() function.
df.idxmax(axis = 0)
输出:A 3
B 0
C 2
dtype: int64