• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / pandas idxmin – Find Index of Minimum Value of Series or DataFrame

pandas idxmin – Find Index of Minimum Value of Series or DataFrame

December 20, 2021 Leave a Comment

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.

Other Articles You'll Also Like:

  • 1.  How to Output XLSX File from Pandas to Remote Server Using Paramiko FTP
  • 2.  Get Python Dictionary Values as List
  • 3.  Using Python to Replace Backslash in String
  • 4.  Python Trig – Using Trigonometric Functions in Python for Trigonometry
  • 5.  Get Year from Date in pandas DataFrame
  • 6.  pandas cumprod – Find Cumulative Product of Series or DataFrame
  • 7.  Check if List is Subset of Another List in Python
  • 8.  How to Group By Columns and Find Mean in pandas DataFrame
  • 9.  Replace Character in String in Python
  • 10.  pandas min – Find Minimum Value of Series or DataFrame

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy