Filip Szczybura
Filip Szczybura

Reputation: 437

How to get the index of row containing min at one and max at second column?

I am storing the information about trained models in a DataFrame:

                              score      time
LogisticRegression            1.0  0.257812
RidgeClassifier               1.0  0.283841
RandomForestClassifier        1.0  0.569159
GradientBoostingClassifier    1.0  9.408432

And I need to find the index (name) of the model, which has highest score and shortest time. How do I do that?

Upvotes: 2

Views: 33

Answers (1)

Mustafa Aydın
Mustafa Aydın

Reputation: 18315

sort_values with ascending one side descending other side:

>>> df.sort_values(["score", "time"], ascending=[False, True]).index[0]
"LogisticRegression"

and get the 0th value in index in the result.

Upvotes: 3

Related Questions