Sometimes after dropping or filtering rows and columns, we may want to reset the indexes of the rows and/or the columns. In the pandas Python library, we can use the reset_index() function for resetting the indexes of the rows and/or the columns. In this article, we will discuss:
- How to reset the indexes of rows of a DataFrame using the pandas Python library?
- How to reset the indexes of columns of a DataFrame using the pandas Python library?
Let’s say we have the following DataFrame:
df1: 0 1 2 3 4 0 1 2 3 4 5 1 6 7 8 9 10 2 11 12 13 14 15 3 16 17 18 19 20
We dropped rows 0, and 2 and columns 1, and 2 from the DataFrame. So, the DataFrame now looks like the following:
df1 after dropping rows and columns: 0 3 4 1 6 9 10 3 16 19 20
Now, we want to reset the indexes of the rows and the columns of the DataFrame.
How to reset the indexes of rows of a DataFrame using the pandas Python library?
In the pandas Python library, we can use the DataFrame.reset_index() function to reset the indexes of the …






0 Comments