I have the following DF which is multi-index due to using groupby():
| date | code | quarter | average |
|---|---|---|---|
| 20201231 | ABCD | Q1 | 3135 |
| Q10 | 3135 | ||
| Q11 | 3135 | ||
| Q12 | 3135 | ||
| Q2 | 3135 |
I'm trying to sort by date, code and then quarter which are part of the multi-index, however I want to use a Natsort method such that the order is Q1, Q2, ....Q9, Q10... but get various errors when I try do so. My best attempt is:
df.sort_index(level=['date','code','quarter'], ascending=[True, True, True], key=natsort_keygen())
I receive the following error:
NotImplementedError: isna is not defined for MultiIndex
I'm using Pandas version 1.1.5, Natsort 8.1.0, Python 3.6.9