8000 BUG: Fix droped result column in groupby with as_index False by phofl · Pull Request #33247 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix droped result column in groupby with as_index False #33247

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add changes requested per review
  • Loading branch information
phofl committed Apr 3, 2020
commit 0605011d9e3596f74eb9a322c9ae8b2e4acaed54
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ Groupby/resample/rolling
- Bug in :meth:`GroupBy.apply` raises ``ValueError`` when the ``by`` axis is not sorted and has duplicates and the applied ``func`` does not mutate passed in objects (:issue:`30667`)
- Bug in :meth:`DataFrameGroupby.transform` produces incorrect result with transformation functions (:issue:`30918`)
- Bug in :meth:`DataFrame.groupby` and :meth:`Series.groupby` produces inconsistent type when aggregating Boolean series (:issue:`32894`)
- Bug in :meth:`DataFrame.groupby` lost results, when ``as_index`` option was set to ``False``. The result values were replaced with the index values (:issue:`32240`).
- Bug in :meth:`DataFrameGroupby.agg` lost results, when ``as_index`` option was set to ``False`` and the result columns were relabeled. The result values were replaced with the index values (:issue:`32240`).


Reshaping
Expand Down
5 changes: 0 additions & 5 deletions pandas/core/groupby/generic.py
5B2F
Original file line number Diff line number Diff line change
Expand Up @@ -969,11 +969,6 @@ def aggregate(self, func=None, *args, **kwargs):
result = result.iloc[:, order]
result.columns = columns

# GH 32240: The groupby function lost the result values if the as_index=False
# option was set and the relabeling flag was true, because the order and
# columns variables do not consider the columns previously set as index.
# Changing the order of relabeling and reseting the index solves this.

if not self.as_index:
self._insert_inaxis_grouper_inplace(result)
result.index = np.arange(len(result))
Expand Down
0