pyspark.pandas.Series.idxmin

Series.idxmin(skipna: bool = True) → Union[Tuple, Any]

Return the row label of the minimum value.

If multiple values equal the minimum, 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 minimum value.

Raises
ValueError

If the Series is empty.

See also

Series.idxmax

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

Notes

This method is the Series version of ndarray.argmin. This method returns the label of the minimum, while ndarray.argmin returns the position. To get the position, use series.values.argmin().

Examples

>>> s = ps.Series(data=[1, None, 4, 0],
...               index=['A', 'B', 'C', 'D'])
>>> s
A    1.0
B    NaN
C    4.0
D    0.0
dtype: float64
>>> s.idxmin()
'D'

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

>>> s.idxmin(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, 0], index=index)
>>> s
first  second
a      c         1.0
       d         NaN
b      e         4.0
       f         0.0
dtype: float64
>>> s.idxmin()
('b', 'f')

If multiple values equal the minimum, 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.idxmin()
10