Skip to content

ENH: Add index=/columns= kwargs to df.set_axis() #45467

@wany-oh

Description

@wany-oh

I think it is strange that .set_axis() can't accept index=/columns= kwargs, even though similar methods .rename(), .rename_axis(), .drop() and etc. can.

Personally, I think it would be more readable than specifying it with 0 or 1.
One trivial advantage is that it allows us to change rows and columns at once.

expect:

>>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
>>> df.set_axis(index=['a', 'b', 'c'])
   A  B
a  1  4
b  2  5
c  3  6

>>> df.set_axis(columns=['I', 'II'])
   I  II
0  1   4
1  2   5
2  3   6

>>> df.set_axis(index=['a', 'b', 'c'], columns=['I', 'II'])
   I  II
a  1   4
b  2   5
c  3   6

Metadata

Metadata

Assignees

Labels

API - ConsistencyInternal Consistency of API/BehaviorEnhancementIndexingRelated to indexing on series/frames, not to indexes themselves

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions