bpd.DataFrame.reset_index

DataFrame.reset_index(*, drop=False)[source]

Reset the index.

Reset the index of the DataFrame, and use the default one instead.

Parameters:drop (bool, default False, keyword only) – Do not try to insert index into dataframe columns. This resets the index to the default integer index.
Returns:
  • DataFrame – DataFrame with the new index.
  • Reset the index of the DataFrame, and use the default one
  • instead. If the DataFrame has a MultiIndex, this method can
  • remove one or more levels.

Examples

>>> df = bpd.DataFrame().assign(name=['Sally', 'George', 'Bill', 'Ann'],
...                             age=[21, 25, 18, 28],
...                             height_cm=[161, 168, 171, 149])
>>> sorted = df.sort_values(by='age')
>>> sorted
     name  age  height_cm
2    Bill   18        171
0   Sally   21        161
1  George   25        168
3     Ann   28        149
>>> sorted.reset_index(drop=True)
     name  age  height_cm
0    Bill   18        171
1   Sally   21        161
2  George   25        168
3     Ann   28        149