Pandas Series: idxmin() function
Row label of the minimum value in Pandas series
The idxmin() function is used to get the row label of the minimum value.
If multiple values equal the minimum, the first row label with that value is returned.
Syntax:
Series.idxmin(self, axis=0, skipna=True, *args, **kwargs)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
skipna | Exclude NA/null values. If the entire Series is NA, the result will be NA. | bool Default Value: True |
Required |
axis | For compatibility with DataFrame.idxmin. Redundant for application on Series. | bool Default Value: 0 |
Required |
*args, **kwargs | Additional keywords have no effect but might be accepted for compatibility with NumPy. | Required |
Returns: Index
Label of the minimum value.
Raises: ValueError
If the Series is empty.
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().
Example:
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series(data=[2, None, 5, 2],
index=['P', 'Q', 'R', 'S'])
s
Output:
P 2.0 Q NaN R 5.0 S 2.0 dtype: float64
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series(data=[2, None, 5, 2],
index=['P', 'Q', 'R', 'S'])
s.idxmin()
Output:
'P'
Example - If skipna is False and there is an NA value in the data, the function returns nan:
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series(data=[2, None, 5, 2],
index=['P', 'Q', 'R', 'S'])
s.idxmin(skipna=False)
Output:
nan
Previous: Get the row label of the maximum value in Pandas series
Next: Find values contained in Pandas series
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook