gaatjeniksaan
gaatjeniksaan

Reputation: 1431

Returning the index value in Pandas

I know this should be obvious, but with previous similar questions I could not get a satisfying answer. Let's say I have a data frame with the index being peoples names and a few columns containing their data (height, male/female, DOB, etc.). Now I want the tallest person in my dataframe and return the corresponding index (their name). So I want the index corresponding to: df['Height'].max()

Thanks in advance!

Upvotes: 0

Views: 229

Answers (1)

Alex
Alex

Reputation: 826

df['Height'] would return a Serie.

Then you should use df['Height'].argmax() or df['Height'].idxmax() to get the corresponding index.

With the links to the documentation :

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.idxmax.html http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.argmax.html

Upvotes: 1

Related Questions