-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Allow to specify column names other than 'level_*' in reset_index() #22260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In [12]: mi = pd.MultiIndex.from_tuples((('a', 1), ('b', 2)), names=['foo', 'bar'])
In [12]: df = pd.DataFrame(index=mi)
In [12]: df.reset_index()
Out[12]:
foo bar
0 a 1
1 b 2 You would be much better served having those names in place prior to the reset. |
I'm ambivalent about this. It's not a super huge ask for this function, but whether it fits semantically into the scope of this function is unclear. cc @jreback |
I personally find it strange, that the function forces defaults name on you without allowing you to change them. I think if we find a proper name for the additional parameter, it would make a nice small improvement |
No col_fill only allows to specify the names of the other levels, if your colums are a Multiindex. However, the actual name of the new index column is not influenced and is set to the default values, if the original index did not have names. |
I am -1 on a new keyword. Names can easily be set before so I don't see this as adding a lot of value |
Thanks for the suggestion! However based on all previous core dev responses I think we can close this one |
I personally find this a regular annoyance with |
Code Sample, a copy-pastable example if possible
Problem description
I often find myself renaming columns after resting the index. I think this could be easily done in one step (see above).
If there is interest in that, I could try to implement it for
Series
andDataFrame
The text was updated successfully, but these errors were encountered: