To find the index of the minimum value of a column in pandas, the easiest way is to use the pandas idxmin() function.

df["Column"].idxmin()

If you are working with a Series object, you can also use idxmin() function.

series.idxmin()

Finding the index of the minimum value of numbers in a column in a DataFrame using pandas is easy. We can use the pandas idxmin() function to find the index of the minimum value in a column of numbers.

Let’s say we have the following DataFrame.

df = pd.DataFrame({'Name': ['Jim', 'Sally', 'Bob', 'Sue', 'Jill', 'Larry'],
                   'Weight': [160.20, 123.81, 209.45, 150.35, 102.43, 187.52]})

print(df)
# Output: 
    Name  Weight
0    Jim  160.20
1  Sally  123.81
2    Bob  209.45
3    Sue  150.35
4   Jill  102.43
5  Larry  187.52

To get the minimum value using pandas in the column “Weight”, we can use the pandas min() function in the following Python code:

print(df["Weight"].min())

# Output:
102.43

From looking at the DataFrame above, we can see that the minimum value has index 4. We confirm that by using the idxmin function below:

print(df["Weight"].idxmin())

# Output:
4

If you are looking to find the index of the maximum value of a set of numbers, you can use the pandas idxmax() function.

Hopefully this article has been helpful for you to understand how to find the index of minimum value of numbers in a Series or DataFrame using idxmin() in pandas.

Categorized in:

Python,

Last Update: February 26, 2024