Python_Learner
Python_Learner

Reputation: 1637

Return Tuple of Index and .max() Value?

I'm trying to return a tuple of the index (the people names below) and the max value for the '%' column below. When I create a Dataframe and try

df['%'].max()

Pandas always returns just the value an not the index. However, I want to create a tuple from the key value pair of the index and max value in the '%' column. I'm sure this is a newbie question, thank you for helping me!

Here's some sample data:

    Points_Scored     Possible_Points    %      Favoriate Food
Jan     60              200              0.3     Pudding
Jane    87              200              0.435   Pizza
Bob     54              200              0.27    Salad
Bubba   42              200              0.21    Salsa
Jack    98              200              0.49    Avacodo
John    45              200              0.225   Bacon
Mike    63              200              0.315   Tacos
Victor  8               200              0.04    Lettuce

Upvotes: 6

Views: 4747

Answers (1)

Zeugma
Zeugma

Reputation: 32105

Here is one way:

df['%'].idxmax(), df['%'].max()

Upvotes: 10

Related Questions