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

Viewed 29

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?

1 Answers

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.

Related