How about we examine how to reset list in Pandas DataFrame. Regularly We start with a tremendous dataframe in Pandas and subsequent to controlling/sifting the dataframe, we end up with a lot more modest dataframe.
At the point when we check out the more modest dataframe, it may in any case convey the line list of the first dataframe. Assuming the first file are numbers, presently we have lists that are not ceaseless. All things considered, pandas has reset_index() work. So to reset the list to the default whole number list starting at 0, We can basically utilize the reset_index() function. By the finish of this article, you will know the various highlights of reset_index work, the boundaries which can be redone to get the ideal result from the capacity. This likewise covers use cases that are firmly connected with doing reset record in pandas.
Allow us to perceive how to reset the file of a DataFrame in the wake of dropping a portion of the lines from the DataFrame.
Approach:
- Import the Pandas module.
- Make a DataFrame.
- Drop a few lines from the DataFrame utilizing the drop() technique.
- Reset the record of the DataFrame utilizing the reset_index() strategy.
- Show the DataFrame after each progression.
# importing the modulesimport pandas as pdimport numpy as np# creating a DataFrameODI_runs = {'name': ['Tendulkar', 'Sangakkara', 'Ponting', 'Jayasurya', 'Jayawardene', 'Kohli', 'Haq', 'Kallis', 'Ganguly', 'Dravid'], 'runs': [18426, 14234, 13704, 13430, 12650, 11867, 11739, 11579, 11363, 10889]}df = pd.DataFrame(ODI_runs)# displaying the original DataFrameprint("Original DataFrame :")print(df)# dropping the 0th and the 1st indexdf = df.drop([0, 1])# displaying the altered DataFrameprint("DataFrame after removing the 0th and 1st row")print(df)# resetting the DataFrame indexdf = df.reset_index()# displaying the DataFrame with new indexprint("Dataframe after resetting the index")print(df) |
Output:


