Choose the sort direction
sort_values() sorts ascending by default. Set ascending=False to put larger values first, then call head(n) to keep the first n rows.
Sort ascending or descending, resolve ties, and take a reproducible top-N result.
Step 1 of 3 · Learn
sort_values() sorts ascending by default. Set ascending=False to put larger values first, then call head(n) to keep the first n rows.
When values tie, add another sort column. The ascending list follows the order of those columns; a unique search ID makes the final order predictable.
| index | id | score |
|---|---|---|
| 0 | 3 | 20 |
| 1 | 1 | 30 |
| 2 | 2 | 30 |
| 3 | 4 | 10 |
| index | id | score |
|---|---|---|
| 1 | 1 | 30 |
| 2 | 2 | 30 |
| 0 | 3 | 20 |
Return search_id and response_ms for the ten slowest searches. Sort response_ms descending, breaking ties by search_id ascending. Save the DataFrame as result.
Loading Python and Pandas…
Run the code to see DataFrame results here.