Skip to content

Add parameter defaults for swaplevel #12934

Closed
@brandon-rhodes

Description

@brandon-rhodes

I will be happy to write up a pull request, but first wanted to gauge the sanity of my suggestion:

I think that swaplevel() deserves default values for its parameters, just like its friends like stack() and unstack() and sortlevel() that also all take an initial level argument. I suggest:

def swaplevel(self, i=-2, j=-1, axis=0):

This provides the greatest symmetry with the other methods that operate on levels: they all, if no level is specified, operate on the innermost level as their default.

In the very common case where there are only two levels to the multi-index anyway, this would reduce this frequent operation to simply .swaplevel() or .swaplevel(axis='columns') without, I don't think, any more loss of readability than when stack() or unstack() fail to specify the level upon which they are operating.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions