Skip to content

ENH: name(s) argument for reset_index? #6878

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

An idea: to be able to specify the a name when resetting the index, which would override the index name or the default value when index name is None.

Eg something like this:

In [10]: df = pd.DataFrame(np.random.rand(4,3), columns=list('ABC'), index=pd.date_range('2013-01-01', periods=4))
In [11]: df
Out[11]: 
                   A         B         C
2013-01-01  0.313664  0.606445  0.048081
2013-01-02  0.907785  0.004429  0.374456
2013-01-03  0.916584  0.067639  0.467712
2013-01-04  0.712824  0.687895  0.397960

In [12]: df.reset_index()
Out[12]: 
       index         A         B         C
0 2013-01-01  0.313664  0.606445  0.048081
1 2013-01-02  0.907785  0.004429  0.374456
2 2013-01-03  0.916584  0.067639  0.467712
3 2013-01-04  0.712824  0.687895  0.397960

In [12]: df.reset_index(name='datetime')
Out[12]: 
    datetime         A         B         C
0 2013-01-01  0.313664  0.606445  0.048081
1 2013-01-02  0.907785  0.004429  0.374456
2 2013-01-03  0.916584  0.067639  0.467712
3 2013-01-04  0.712824  0.687895  0.397960

For multi-index, you should provide a list.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementIndexRelated to the Index class or subclasses

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions