pandas.Series.idxmax¶
Return the row label of the maximum value.
If multiple values equal the maximum, the first row label with that value is returned.
- param skipna
- bool, default True
Exclude NA/null values. If the entire Series is NA, the result will be NA.
- param axis
- int, default 0
For compatibility with DataFrame.idxmax. Redundant for application on Series. *args, **kwargs Additional keywords have no effect but might be accepted for compatibility with NumPy.
- return
Index Label of the maximum value.
- raises
- ValueError
If the Series is empty.
Limitations¶
Parameter axis
is supported only with default value None
.
Parameter skipna
cannot be False
with data of string type.
Examples¶
Getting the row label of the maximum value.¶
import numpy as np
import pandas as pd
from numba import njit
@njit
def series_idxmax():
s = pd.Series([4, np.nan, 2, 1], index=['A', 'B', 'C', 'D'])
return s.idxmax() # Expect index of maximum value A
print(series_idxmax())
$ python ./series/series_idxmax.py
A
See also
- Series.idxmin
Return index label of the first occurrence of minimum of values.
- numpy.absolute
Return indices of the maximum values along the given axis.
- DataFrame.idxmax
Return index of first occurrence of maximum over requested axis.