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.
Reversing the rows of a data frame in pandas can be done in python by invoking the loc() function. The panda's dataframe. loc() attribute accesses a set of rows and columns in the given data frame by either a label or a boolean array.
Only consider certain columns for identifying duplicates, by default use all of the columns. Determines which duplicates (if any) to keep. - first : Drop duplicates except for the first occurrence.
Check out http://pandas.pydata.org/pandas-docs/stable/indexing.html
You can do
reversed_df = df.iloc[::-1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With