-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Keep series name when merging GroupBy result #6068
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
ENH: Keep series name when merging GroupBy result #6068
Conversation
does this have an associated issue? |
I didn't create an issue. Should I? |
you don't have to, but pls put an example of what is wrong, and then what this PR does in the top section e.g. this feature is missing, this PR makes it do ..... |
Updated |
actually...why don't you create an issue for this....that way can tag it with some labels..... |
No problem. Made an issue. Thanks for looking at this. |
Updated docs to reflect a pagination bug that was fixed. Closes: issue #6068
can you rebase? |
hows this coming? |
yes force pushing is correct |
pls add in a tests for #6265 (and release note mention) as well..thanks |
Rebased, added tests, made sure tests passed, fixed as per discussion in #6124 and added release note mention. |
FYI, did another rebase/force push. |
this looks really good! can you add the example (in the top of the PR) to the groupby.rst/examples section (just the fixed version). If you are really adventurous, you can put a 1-liner v0.14.0 under API changes with a reference to this. Its not an API change, but useful to know. |
Added the example. There was already a note in the release file about the changes (it's more than one line though). Let me know if that should be shortened. |
minor issue |
When possible, attempt to preserve the series name when performing groupby operations. This facilitates reshaping/indexing operations on the result of the groupby/apply or groupby/agg operation. Fixes GH6265 and GH6124. Added example to groupby.rst and description to API changes for v0.14.
Done. Amended previous commit and force-updated. |
…_apply_series_name ENH: Keep series name when merging GroupBy result
thanks @bburan-galenea this was a great effort! |
closes #6124
closes #6265
Use case
This will facilitate DataFrame group/apply transformations when using a function that returns a Series. Right now, if we perform the following:
We get the following output:
Ideally, the series name should be preserved and propagated through these operations such that we get the following output:
The only way to achieve this (currently) is:
However, the key issue here is 1) this adds an extra line of code and 2) the name of the series created in the applied function may not be known in the outside block (so we can't properly fix the result.columns.name attribute).
The other work-around is to name the index of the series:
During the group/apply operation, this pull request will check to see whether series.index has the name attribute set. If the name attribute is not set, it will set the index.name attribute to the name of the series (thus ensuring the name propagates).