Series.reset_index(level=None, drop=False, name=_NoDefault.no_default, inplace=False)[source]#

Reset the index of the Series, or a level of it.

levelint, str, tuple, or list, default None

Only remove the given levels from the index. Removes all levels by default.

dropbool, default False

Do not try to insert index into dataframe columns. This resets the index to the default integer index.

nameobject, optional

The name to use for the column containing the original Series values. Uses by default. This argument is ignored when drop is True.

inplacebool, default False

Modify the DataFrame in place (do not create a new object).

Series or DataFrame or None

Series with the new index or None if inplace=True. For Series, 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.


>>> series = cudf.Series(['a', 'b', 'c', 'd'], index=[10, 11, 12, 13])
>>> series
10    a
11    b
12    c
13    d
dtype: object
>>> series.reset_index()
   index  0
0     10  a
1     11  b
2     12  c
3     13  d
>>> series.reset_index(drop=True)
0    a
1    b
2    c
3    d
dtype: object

You can also use reset_index with MultiIndex.

>>> s2 = cudf.Series(
...             range(4), name='foo',
...             index=cudf.MultiIndex.from_tuples([
...                     ('bar', 'one'), ('bar', 'two'),
...                     ('baz', 'one'), ('baz', 'two')],
...                     names=['a', 'b']
...      ))
>>> s2
a    b
bar  one    0
     two    1
baz  one    2
     two    3
Name: foo, dtype: int64
>>> s2.reset_index(level='a')
       a  foo
one  bar    0
two  bar    1
one  baz    2
two  baz    3