w3resource

Pandas Series: reset_index() function

Generate a new Pandas series with the index reset

The reset_index() function is used to generate a new DataFrame or Series with the index reset.

This is useful when the index needs to be treated as a column, or when the index is meaningless and needs to be reset to the default before another operation

Syntax:

Series.reset_index(self, level=None, drop=False, name=None, inplace=False)
Pandas Series reset_index image

Parameters:

Name Description Type/Default Value Required / Optional
level For a Series with a MultiIndex, only remove the specified levels from the index. Removes all levels by default. int, str, tuple, or list, optional
drop Just reset the index, without inserting it as a column in the new DataFrame. bool
Default Value: False
Required
name The name to use for the column containing the original Series values. Uses self.name by default. This argument is ignored when drop is True. object optional
inplace Modify the Series in place (do not create a new object). bool
Default Value: False
Required

Returns:Series or DataFrame
When drop is False (the default), a DataFrame is returned. The newly created columns will come first in the DataFrame, followed by the original Series values. When drop is True, a Series is returned. In either case, if inplace=True, no value is returned.

Example:


Download the above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts