How to use iloc() function to Reverse Row In Python Pandas

Reversing the rows of a data frame in pandas can be done in python by invoking the iloc() function.  Let us know how to reverse the rows of a data frame in pandas.

Syntax: DataFrame.iloc[]

Parameters: Index Position: Index position of rows in integer or list of integer.

Return: Data frame or Series depending on parameters

Python3




# Reverse rows using iloc() Function
Data_reverse_row_1 = dataframe.iloc[::-1]
 
# Observe the result
Data_reverse_row_1


Output:

reversed database

How to Reverse Row in Pandas DataFrame?

In this article, we will learn how to reverse a row in a pandas data frame using Python

With the help of Pandas, we can perform a reverse operation by using loc(), iloc(), reindex(), slicing, and indexing on a row of a data set. 

Similar Reads

Creating Dataframe

Let’s create a simple data frame with a dictionary, say column names are: ‘Income’, ‘Expenses’, ‘Profit’....

Using iloc() function to Reverse Row

...

Using loc() function to Reverse Row

Reversing the rows of a data frame in pandas can be done in python by invoking the iloc() function.  Let us know how to reverse the rows of a data frame in pandas....

Using reindex() function to Reverse Row

...

Using dataframe indexing to Reverse Row

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....

Using the reset_Index() function to Reverse Row

...