18

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.

valentin
  • 2,596
  • 6
  • 28
  • 48

1 Answers1

40

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

You can do

reversed_df = df.iloc[::-1]
Mike Graham
  • 73,987
  • 14
  • 101
  • 130