- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Get the Position of Minimum Value of a pandas Series?
To get the position of minimum value of a pandas series object we can use a function called argmin().
The argmin() is the method of the pandas series constructor, which is used to get the row position of the smallest value from the series. The output of the argmin() method is an integer value. If the pandas series object having the Nan values, then the argmin() method will identify the smallest number by neglecting those Nan values.
If the minimum value is located in multiple index positions, then the first occurrence value position is taken as output.
Example 1
# import pandas package import pandas as pd import numpy as np # create a pandas series s = pd.Series(np.random.randint(1,100, 10)) print(s) # Apply argmin function print('Output of argmin:', s.argmin())
Explanation
Let’s create a pandas series object with 10 random integer values between 1 to 100 range and then apply the argmin function to get the position of minimum value of the series object.
Initially, we have imported the NumPy package for creating a range of random integer values.
Output
0 76 1 58 2 42 3 81 4 7 5 85 6 75 7 25 8 61 9 57 dtype: int32 Output of argmin: 4
The argmin() method of pandas series object is returned an integer value “4” for the following example, and that integer value represents the position of the minimum value of the given series object.
Example 2
import pandas as pd # creating range sequence of dates dates = pd.date_range('2021-06-01', periods=6, freq='D') #creating pandas Series with date index s = pd.Series([43,21,40,54,10,23], index= dates) print (s) # Apply argmin function print('Output of argmin:', s.argmin())
Explanation
Let’s create another pandas series object using a list of integers with date_range index labels. After that, apply the argmin() method over the data of the series object “s” to get the position of the minimum value of the given series object.
Output
2021-06-01 43 2021-06-02 21 2021-06-03 40 2021-06-04 54 2021-06-05 10 2021-06-06 23 Freq: D, dtype: int64 Output of argmin: 4
The output of the argmin() method for this example is integer value “4”, which means the value at index label “2021-06-05” is having a minimum value over the data present in the given series object.
- Related Articles
- How to Get the Position of Max Value of a pandas Series?
- How to access a single value in pandas Series using the integer position?
- How to get the nth percentile of a Pandas series?
- How to get the index and values of series in Pandas?
- Python Pandas - Get the minimum value from Ordered CategoricalIndex
- How to get the length, size, and shape of a series in Pandas?
- How to get a value from the cell of a Pandas DataFrame?
- Python - Return the minimum value of the Pandas Index
- How to get the final rows of a time series data using pandas series.last() method?
- How to get few rows from a Series in Pandas?
- How to get the nth value of a Fibonacci series using recursion in C#?
- How to check each value of a pandas series is unique or not?\n
- Python Pandas - Return the minimum value of the Timedelta object
- How to Get the values from the pandas series between a specific time?
- How to check the data type of a pandas series?
