- 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 Max Value of a pandas Series?

In the pandas series constructor, there is a method called argmax() which is used to get the position of maximum value over the series data.

The pandas series is a single-dimensional data structure object with row index values. By using row index values we can access the data.

The argmax() method in the pandas series is used to get the positional index of the maximum value of the series object. The output of the argmax method is an integer value, which refers to the position where the largest value exists.

## Example 1

# import pandas package import pandas as pd import numpy as np # create a pandas series s = pd.Series(np.random.randint(10,100, 10)) print(s) # Apply argmax function print('Output of argmax', s.argmax())

## Explanation

Let’s create a pandas series object with 10 random integer values between 10 to 100 range and apply the argmax() function to get the position of the max value over the series values.

## Output

0 81 1 94 2 75 3 13 4 17 5 42 6 45 7 29 8 25 9 59 dtype: int32 Output of argmax: 1

The argmax() method of pandas series object is returned an integer value “1” for the following example, and that integer value represents the position of the maximum value of the given series element.

## Example 2

import pandas as pd import numpy as np # creating pandas Series object series = pd.Series({'Black':10, 'White':29,'Red':82, 'Blue':56,'Green':67}) print(series) # Apply argmax function print('Output of argmax:',series.argmax())

## Explanation

In the following example, we have created a pandas.Series object “series” using a python dictionary, and the resultant series is having named index labels with integer data. After that, we applied the argmax() method over the data of the series object to get the position of the maximum number.

## Output

Black 10 White 29 Red 82 Blue 56 Green 67 dtype: int64 Output of argmax: 2

The output of the argmax() method is 2 for the following example, which means the value at index label “Red” is having a maximum value.

If the maximum value is available in multiple locations, then the argmax method will return the first-row position as output.

- Related Articles
- How to Get the Position of Minimum 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?
- 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?
- 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
- How to Get the values from the pandas series between a specific time?
- How to check the data type of a pandas series?
- How to get the max of two values MySQL?
- How to access a single value in pandas Series using the .at attribute?
- Python Pandas - Return the int position of the smallest value in the Index