-1

I found the answer on how to reverse the order of a python series in this stackoverflow answer. reverse dataframe's rows' order with pandas

They referenced this page as their source : http://pandas.pydata.org/pandas-docs/stable/indexing.html, but I was unable to find the exact section on the page where the strategy for reverse indexing was explained. Could someone please help me with this or direct me to where in the pandas/python documentation this strategy is outlined.

Anna T
  • 11
  • 5
  • There is no built-in method in `pandas` to reverse the order of a `DataFrame`, hence why you wont find any specific information on that in the documentation. In order to reverse a `DataFrame` you will have to use either `reversed()` (which is a function that is part of the standard library of `python`) or use `slice` notation as suggested in the thread you link to. Neither slice notation nor `reversed()` are methods specific to `pandas`. – user3471881 Nov 30 '18 at 10:36
  • You can however see the slicing notation of reversing an object in action in the docs here: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-with-isin and in some other places as well. – user3471881 Nov 30 '18 at 10:39

3 Answers3

1

To anyone else who might be searching for this, the above answer gave a really good link to explain the concept: Understanding Python's slice notation

As an answer to the question "Where in the documentation does it say this?" Python documentation explains basic slicing here : Basic Slicing in Documentation

The functionality of steps (or increments) is then explained here in the updates for python 2.3 Slicing with steps explained

Anna T
  • 11
  • 5
0

I think you ought to read about slicing: Understanding Python's slice notation

For different ways to reverse a df, look here: Right way to reverse pandas.DataFrame?

Martin
  • 52
  • 5
  • Hello, I think you misunderstood my question. I understand how to reverse a dataframe, stackoverflow was very helpful with that. I want to know where in the documentation it tells you how to reverse a dataframe. – Anna T Nov 30 '18 at 10:26
  • I don't think it says explicitly in the Pandas documentation why df[::-1] reverses a df. Slicing using [::] notation is a general Python concept. – Martin Nov 30 '18 at 10:37
  • Ok, so that first link you posted : Understanding Python's slice notation was good. I am basically looking for the place in the python documentation where it says that, since as you say, it is a basic python concept. Again I understood the concept from before, i am trying to learn my way around the official language documentation. – Anna T Nov 30 '18 at 11:17
0

In case if you are trying to just reverse the indexing order keeping the order of the data unaltered try

df.index = reversed(df.index)
Loochie
  • 2,414
  • 13
  • 20