Home > Software engineering >  Reordering Index to a specific order
Reordering Index to a specific order

Time:12-31

I have a dataframe called exam and I would like to sort the month column (which is the index) according to the common order (Jan, feb, mar, apr, etc). However, it seems to be sorted in ascending order. I tried the reindex command but it didn't make a difference. How can I order it as I want?

Here is the code

exam.reindex(['January','February','March','April','May','June','July','August','September','October','November'])

Here is the dataframe enter image description here

CodePudding user response:

You need to assign it back

exam = exam.reindex(['January','February','March','April','May','June','July','August','September','October','November'])

CodePudding user response:

Try this:

new_index = ['January','February','March','April','May','June','July','August','September','October','November']
exam = exam.loc[new_index]
  • Related