Signup/Sign In

Pandas Series argmax() Method

In this tutorial, we will learn the python pandas Series.argmax() method. This function returns the integer value which indicates the position where the largest value exists.

The below shows the syntax of the Series.argmax() method.

Syntax

Series.argmax(axis=None, skipna=True, *args, **kwargs)

Parameters

axis: It is None. It is the dummy argument for consistency with Series.

skipna: It is the bool(True or False), and the default value is True. It excludes all null values when showing the result.

*args, **kwargs: It is the additional arguments and keywords for compatibility with NumPy.

Example: Get the Position of max Value using the Series.argmax() Method

Let's apply the Series.argmax() method to the two Series and get the position of the larger value. See the below example.

Here, in Series s_1, there are different values and in s_2, it consists of repeated values. The Series.argmax() method returns a position and if the larger value present in a different location, it returns the position of the first row.

#importing pandas as pd
import pandas as pd
#creating Series
s_1= pd.Series([12,45,78,22])
s_2= pd.Series([11,45,14,45])
print("In Series s_1 the maximum value is in position:",s_1.argmax())
print("In Series s_2 the maximum value is in position:",s_2.argmax())


In Series s_1 the maximum value is in position: 2
In Series s_2 the maximum value is in position: 1

Example: Get thePosition of a mx value consists of null values

Here, in this example, the Series elements consist of null values, and by default the Series.argmax() method ignores the null values and returns the position of the larger value just by considering the integer elements. See the below example.

#importing pandas as pd
import pandas as pd
#importing numpy as np
import numpy as np
#creating Series
s = pd.Series([np.nan,12,100,np.nan])
print("The maximum value is in position:",s.argmax())


The maximum value is in position: 2

Conclusion

In this tutorial, we understand the Series.argmax() method of the data frame. We learned the syntax and parameters of Series.argmax() method and created different examples to better understand this topic.



About the author:
I like writing about Python, and frameworks like Pandas, Numpy, Scikit, etc. I am still learning Python. I like sharing what I learn with others through my content.