pyspark.pandas.Series.idxmax#

Series.idxmax(skipna=True)[source]#

Return the row label of the maximum value.

If multiple values equal the maximum, the first row label with that value is returned.

Parameters
skipnabool, default True

Exclude NA/null values. If the entire Series is NA, the result will be NA.

Returns
Index

Label of the maximum value.

Raises
ValueError

If the Series is empty.

See also

Series.idxmin

Return index label of the first occurrence of minimum of values.

Examples

>>> s = ps.Series(data=[1, None, 4, 3, 5],
...               index=['A', 'B', 'C', 'D', 'E'])
>>> s
A    1.0
B    NaN
C    4.0
D    3.0
E    5.0
dtype: float64
>>> s.idxmax()
'E'

If skipna is False and there is an NA value in the data, the function returns nan.

>>> s.idxmax(skipna=False)
nan

In case of multi-index, you get a tuple:

>>> index = pd.MultiIndex.from_arrays([
...     ['a', 'a', 'b', 'b'], ['c', 'd', 'e', 'f']], names=('first', 'second'))
>>> s = ps.Series(data=[1, None, 4, 5], index=index)
>>> s
first  second
a      c         1.0
       d         NaN
b      e         4.0
       f         5.0
dtype: float64
>>> s.idxmax()
('b', 'f')

If multiple values equal the maximum, the first row label with that value is returned.

>>> s = ps.Series([1, 100, 1, 100, 1, 100], index=[10, 3, 5, 2, 1, 8])
>>> s
10      1
3     100
5       1
2     100
1       1
8     100
dtype: int64
>>> s.idxmax()
3