WIP: keep column levels when using apply after grouping (#16231)
State: closed

 - [X] closes #16231
 - [X] 3 tests added / passed
 - [X] passes ``git diff upstream/master --name-only -- '*.py' | flake8 --diff``
 - [X] whatsnew entry

This is still experimental-- the groupby logic is awfully complicated at this point, and there are lots of edge cases.

Labels:
name: Bug
name: Groupby

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16651?src=pr&el=h1) Report
> Merging [#16651](https://codecov.io/gh/pandas-dev/pandas/pull/16651?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9fdea65e5675f724efbb6afd68b5862128aa388d?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #16651      +/-   ##
==========================================
+ Coverage   90.93%   90.93%   +<.01%     
==========================================
  Files         161      161              
  Lines       49265    49269       +4     
==========================================
+ Hits        44800    44804       +4     
  Misses       4465     4465
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.69% <100%> (ø)` | :arrow_up: |
| #single | `40.22% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16651?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/16651?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYmFzZS5weQ==) | `96.23% <100%> (+0.01%)` | :arrow_up: |
| [pandas/core/groupby.py](https://codecov.io/gh/pandas-dev/pandas/pull/16651?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS5weQ==) | `92.08% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16651?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/16651?src=pr&el=footer). Last update [9fdea65...37a0195](https://codecov.io/gh/pandas-dev/pandas/pull/16651?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16651?src=pr&el=h1) Report
> Merging [#16651](https://codecov.io/gh/pandas-dev/pandas/pull/16651?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/ceaf85233d434a226b23f891465b4abfdc602e46?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #16651      +/-   ##
==========================================
+ Coverage   90.93%   90.93%   +<.01%     
==========================================
  Files         161      161              
  Lines       49266    49270       +4     
==========================================
+ Hits        44801    44805       +4     
  Misses       4465     4465
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.69% <100%> (ø)` | :arrow_up: |
| #single | `40.22% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16651?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/16651?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYmFzZS5weQ==) | `96.23% <100%> (+0.01%)` | :arrow_up: |
| [pandas/core/groupby.py](https://codecov.io/gh/pandas-dev/pandas/pull/16651?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS5weQ==) | `92.08% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16651?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/16651?src=pr&el=footer). Last update [ceaf852...078a0ce](https://codecov.io/gh/pandas-dev/pandas/pull/16651?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

can you rebase (and move whatsnew to 0.21.0)
closing as stale. if you'd like to continue working, pls ping.