reverse dataframe's rows' order with pandas

valentin picture valentin · Feb 6, 2016 · Viewed 19k times · Source

How can I reverse the order of the rows in my pandas.dataframe?

I've looked everywhere and the only thing people are talking about is sorting the columns, reversing the order of the columns...

What I want is simple :

If my DataFrame looks like this:

   A      B     C
 ------------------
  LOVE    IS   ALL
  THAT   MAT   TERS

I want it to become this:

   A      B     C
 ------------------
  THAT   MAT   TERS
  LOVE    IS   ALL

I know I can iterate over my data in reverse order but that's not what I want.

Answer

Mike Graham picture Mike Graham · Feb 6, 2016

Check out http://pandas.pydata.org/pandas-docs/stable/indexing.html

You can do

reversed_df = df.iloc[::-1]