Search code examples
pythonpython-3.xpandasdataframereindex

Reordering Index to a specific order


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


Solution

  • You need to assign it back

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