Let’s discuss how to reset index in Pandas DataFrame. Often We start with a huge dataframe in Pandas and after manipulating/filtering the dataframe, we end up with much smaller dataframe.
When we look at the smaller dataframe, it might still carry the row index of the original dataframe. If the original index are numbers, now we have indexes that are not continuous. Well, pandas has
reset_index() function. So to reset the index to the default integer index beginning at 0, We can simply use the
So let’s see the different ways we can reset the index of a DataFrame.
First see original DataFrame.
Example #1: Make Own Index Without Removing Default index.
Example #2: Make Own Index and Removing Default index.
Example 3: Reset own index and make default index as index.
Example #4: Make a column of dataframe as index with remove default index.
Example 5: Make a column of dataframe as index without remove default index.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Pandas - How to reset index in a given DataFrame
- How to reset a form using jQuery with .reset() method?
- Convert given Pandas series into a dataframe with its index as another column on the dataframe
- Python | Pandas DataFrame.fillna() to replace Null values in dataframe
- Pandas Dataframe.to_numpy() - Convert dataframe to Numpy array
- How to Convert Wide Dataframe to Tidy Dataframe with Pandas stack()?
- How to get rows/index names in Pandas dataframe
- Return the Index label if some condition is satisfied over a column in Pandas Dataframe
- How to Convert Dataframe column into an index in Python-Pandas?
- How to drop rows in Pandas DataFrame by index labels?
- How to Convert Index to Column in Pandas Dataframe?
- How to Sort a Pandas DataFrame based on column names or row index?
- Get minimum values in rows or columns with their index position in Pandas-Dataframe
- Select Rows & Columns by Name or Index in Pandas DataFrame using [ ], loc & iloc
- Get column index from column name of a given Pandas DataFrame
- Create a Pandas DataFrame from a Numpy array and specify the index column and column headers
- How to convert index in a column of the Pandas dataframe?
- Split Pandas Dataframe by Column Index
- Determine Period Index and Column for DataFrame in Pandas
- How to reset/remove CSS styles for element ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.