API: Add DataFrame.droplevel
State: closed

- [x] closes #20342
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Labels:
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves
name: API Design
name: MultiIndex

Comments:
Hello @vbarda! Thanks for updating the PR.







Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on July 19, 2018 at 13:18 Hours UTC
Thanks for the contribution @vbarda.

From the issue, I'd say we want this method in index, not in DataFrame. @TomAugspurger can you please confirm?

Also, you're missing adding a comment to the whatsnew documentation (if you don't know how to do it, you can check closed PRs to see how it's done).
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21871?src=pr&el=h1) Report
> Merging [#21871](https://codecov.io/gh/pandas-dev/pandas/pull/21871?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9d94a95c48b55f517569a00aafb3d378f05bd80f?src=pr&el=desc) will **increase** coverage by `0.05%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/21871/graphs/tree.svg?token=eZ4WkYLtcO&src=pr&height=150&width=650)](https://codecov.io/gh/pandas-dev/pandas/pull/21871?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #21871      +/-   ##
==========================================
+ Coverage   91.91%   91.96%   +0.05%     
==========================================
  Files         164      166       +2     
  Lines       49987    50334     +347     
==========================================
+ Hits        45947    46292     +345     
- Misses       4040     4042       +2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.36% <100%> (+0.06%)` | :arrow_up: |
| #single | `42.22% <20%> (+0.06%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/21871?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/21871/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `96.47% <100%> (+0.01%)` | :arrow_up: |
| [pandas/core/indexes/timedeltas.py](https://codecov.io/gh/pandas-dev/pandas/pull/21871/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy90aW1lZGVsdGFzLnB5) | `91.53% <0%> (-0.65%)` | :arrow_down: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/21871/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.35% <0%> (-0.23%)` | :arrow_down: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/21871/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.16% <0%> (-0.18%)` | :arrow_down: |
| [pandas/core/algorithms.py](https://codecov.io/gh/pandas-dev/pandas/pull/21871/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWxnb3JpdGhtcy5weQ==) | `94.69% <0%> (-0.16%)` | :arrow_down: |
| [pandas/io/packers.py](https://codecov.io/gh/pandas-dev/pandas/pull/21871/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhY2tlcnMucHk=) | `88.04% <0%> (-0.16%)` | :arrow_down: |
| [pandas/core/reshape/merge.py](https://codecov.io/gh/pandas-dev/pandas/pull/21871/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9tZXJnZS5weQ==) | `94.1% <0%> (-0.16%)` | :arrow_down: |
| [pandas/core/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/21871/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tbW9uLnB5) | `92.08% <0%> (-0.12%)` | :arrow_down: |
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/21871/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `93.17% <0%> (-0.04%)` | :arrow_down: |
| [pandas/core/dtypes/common.py](https://codecov.io/gh/pandas-dev/pandas/pull/21871/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2NvbW1vbi5weQ==) | `95.07% <0%> (ø)` | :arrow_up: |
| ... and [28 more](https://codecov.io/gh/pandas-dev/pandas/pull/21871/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21871?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21871?src=pr&el=footer). Last update [9d94a95...6b8f22b](https://codecov.io/gh/pandas-dev/pandas/pull/21871?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@datapythonista 

> From the issue, I'd say we want this method in index, not in DataFrame. @TomAugspurger can you please confirm?

it already exists for ``Index``, this is exposing on Series/DataFrame.

Thank you for the comments -- addressing the changes now
thanks @vbarda  nice patch!

can you create an issue about adding ``inplace`` to ``.droplevel``.
Thank you -- will add the issue now!
Added here: https://github.com/pandas-dev/pandas/issues/21990