Examples
import numpy as np
import pandas as pd
s = pd.Series([2, 3, 4, 5], name='f1',
index=pd.Index(['p', 'q', 'r', 's'], name='idx'))
Generate a DataFrame with default index.
s.reset_index()
To specify the name of the new column use name.
s.reset_index(name='values')
To generate a new Series with the default set drop to True.
s.reset_index(drop=True)
To update the Series in place, without generating a new one set inplace to True. Note that it also
requires drop=True.
s.reset_index(inplace=True, drop=True)
s
The level parameter is interesting for Series with a multi-level index.
arrays = [np.array(['b1', 'b2', 's1', 's2']),
np.array(['one', 'two', 'one', 'two'])]
s2 = pd.Series(
range(4), name='f1',
index=pd.MultiIndex.from_arrays(arrays,
names=['p', 'q']))
To remove a specific level from the Index, use level.
s2.reset_index(level='p')
If level is not set, all levels are removed from the Index.
s2.reset_index()