Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Get Location of Max Value in a Pandas Series

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

import pandas as pd
s = pd.Series(data=[1, None, 4, 3, 4], index=["A", "B", "C", "D", "E"])
s
A 1.0 B NaN C 4.0 D 3.0 E 4.0 dtype: float64

pandas.DataFrame.idxmax

Return index of first occurrence of maximum over requested axis. NA/null values are excluded.

s.idxmax()
'C'

pandas.Series.argmax

Return int position of the largest value in the Series. If the maximum is achieved in multiple locations, the first row position is returned.

s.argmax()
2

Sort & Take Top Rows