-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
API: Add DataFrame.droplevel #20342
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
@woohoo! I'd love for this to come into pandas, so that I don't have to worry about implementing it in pyjanitor! (Issue on my own package, which I'm more than willing to close if this happens: pyjanitor-devs/pyjanitor#8) |
Also, a hacky implementation to hopefully kickstart things: https://github.com/ericmjl/pyjanitor/blob/index-manipulation/janitor/functions.py#L324 and |
Thanks @TomAugspurger! This would be a great addition. One could make the same case for all other Index methods that return an index besides |
Not against this, but will it have any different functionality than Seems like that covers what you'd want to do, unless I'm misinterpreting what this is supposed to do: In [2]: df = pd.DataFrame(np.arange(16).reshape(4, 4), columns=list('abcd')).set_index(list('abc'))
In [3]: df
Out[3]:
d
a b c
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
In [4]: df.reset_index(level=1, drop=True)
Out[4]:
d
a c
0 2 3
4 6 7
8 10 11
12 14 15
In [5]: df.reset_index(level='c', drop=True)
Out[5]:
d
a b
0 1 3
4 5 7
8 9 11
12 13 15
In [6]: df.reset_index(level=['a', 'c'], drop=True)
Out[6]:
d
b
1 3
5 7
9 11
13 15 |
Ah, good point. I suspect that covers all the needs.
This would be good to document in reset_index and in MultiIndex.droplevel.
…On Wed, Mar 14, 2018 at 11:47 AM, jschendel ***@***.***> wrote:
Not against this, but will it have any different functionality than
reset_index with drop=True?
Seems like that covers a lot of what you'd want to do:
In [2]: df = pd.DataFrame(np.arange(16).reshape(4, 4), columns=list('abcd')).set_index(list('abc'))
In [3]: df
Out[3]:
d
a b c0 1 2 34 5 6 78 9 10 1112 13 14 15
In [4]: df.reset_index(level=1, drop=True)
Out[4]:
d
a c0 2 34 6 78 10 1112 14 15
In [5]: df.reset_index(level='c', drop=True)
Out[5]:
d
a b0 1 34 5 78 9 1112 13 15
In [6]: df.reset_index(level=['a', 'c'], drop=True)
Out[6]:
d
b1 35 79 1113 15
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#20342 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQHIg2mu7QcbSgsWAfFPM-vKhZmLflmks5teUm2gaJpZM4SqWfj>
.
|
Don't think it totally covers everything...sometimes find a need to drop a column-index level, and i don't think reset_index supports columns (for good reason) |
@jschendel had a good point that this will overlap with
I don't have a strong opinion on whether we should add it, or better document reset_index. |
As a way to make dropping an index level possible in an method chain.
roughly equivalent to
cc @twiecki
The text was updated successfully, but these errors were encountered: