Premium problem119. Sort by a Custom Priority Order

Medium Locked

orders has columns order_id and priority, where priority is one of "low", "medium", "high", "critical".

Sort the rows most urgent first, so critical, then high, then medium, then low, breaking ties by order_id. Renumber the index from 0 and leave priority as an ordered categorical so the ordering travels with the column.

Alphabetical sorting puts "critical" before "low", which is right by accident and wrong in general; mapping to numbers loses the labels.

Input

   order_id  priority
0         1    medium
1         2  critical
2         3       low
3         4      high
4         5  critical

Output

   order_id  priority
0         2  critical
1         5  critical
2         4      high
3         1    medium
4         3       low

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)