Python Pandas - Return the int position of the largest value in the Index

The argmax() method in Pandas returns the integer position of the largest value in an Index. This is useful when you need to locate the position rather than the actual maximum value.

Syntax

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

Parameters

skipna: bool, default True. Exclude NA/null values when showing the result.

Creating a Pandas Index

First, let's create an Index with numeric values ?

import pandas as pd

# Creating the index
index = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55])
print("Pandas Index...")
print(index)
Pandas Index...
Index([15, 25, 55, 10, 100, 70, 35, 40, 55], dtype='int64')

Finding Position of Maximum Value

Use argmax() to get the integer position of the largest value ?

import pandas as pd

index = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55])

# Get the int position of the largest value
position = index.argmax()
print(f"Position of maximum value: {position}")
print(f"Maximum value at position {position}: {index[position]}")
Position of maximum value: 4
Maximum value at position 4: 100

Complete Example

Here's a comprehensive example showing Index properties and the position of maximum value ?

import pandas as pd

# Creating the index
index = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55])

# Display the index
print("Pandas Index...")
print(index)

# Return a tuple of the shape of the underlying data
print("\nA tuple of the shape of underlying data...")
print(index.shape)

# Return the number of elements in the Index
print("\nNumber of elements in the index...")
print(index.size)

# The int position of the largest value in the Index
print("\nGet the int position of the largest value in the Index...")
print(index.argmax())
Pandas Index...
Index([15, 25, 55, 10, 100, 70, 35, 40, 55], dtype='int64')

A tuple of the shape of underlying data...
(9,)

Number of elements in the index...
9

Get the int position of the largest value in the Index...
4

Handling Duplicate Maximum Values

When there are duplicate maximum values, argmax() returns the position of the first occurrence ?

import pandas as pd

# Index with duplicate maximum values
index = pd.Index([10, 50, 30, 50, 20])

print("Index with duplicate max values:")
print(index)
print(f"\nPosition of first maximum value: {index.argmax()}")
print(f"Maximum value: {index.max()}")
Index with duplicate max values:
Index([10, 50, 30, 50, 20], dtype='int64')

Position of first maximum value: 1
Maximum value: 50

Conclusion

The argmax() method returns the integer position of the largest value in a Pandas Index. When duplicate maximum values exist, it returns the position of the first occurrence. This is useful for locating rather than retrieving the maximum value itself.

Updated on: 2026-03-26T16:16:00+05:30

178 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements