Skip to content
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

Missing Series name when using count() on groupby object #6265

Closed
andygoldschmidt opened this issue Feb 5, 2014 · 3 comments · Fixed by #6068
Closed

Missing Series name when using count() on groupby object #6265

andygoldschmidt opened this issue Feb 5, 2014 · 3 comments · Fixed by #6068
Labels
Bug Groupby Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@andygoldschmidt
Copy link

Consider this very basic group by operation:

df = pd.DataFrame({'col1': ['a', 'b', 'a', 'c'], 'col2': [1, 3, 2, 5]})
df_grp = df.groupby('col1')['col2']

When aggregating using mean, min, ... (everything but count) the resulting Series has col2 as its name:

df_grp.mean()

col1
a       1.5
b       3.0
c       5.0
Name: col2, dtype: float64

However, if I use count for aggregation, the name is not set:

df_grp.count()

col1
a       2
b       1
c       1
dtype: int64

Not a big problem for a simple case like that, but I stumbled over that while working with a MultiIndex that needed to be reindexed and led to a KeyError due to that missing column name.

@jreback
Copy link
Contributor

jreback commented Feb 5, 2014

dup of #6124, closed by #6068

@bburan-galenea
Copy link
Contributor

@jreback - Apologies for the delayed response, I have been out of the country for a few weeks. This does not appear to be a duplicate of #6124 and I verified that #6068 does not fix the problem

The problem described in this issue can be traced to SeriesGroupBy._wrap_applied_output where it just returns an (unnamed) series.

@jreback
Copy link
Contributor

jreback commented Feb 24, 2014

ok thanks
do you want to try to incorporate a fix for that issue as well ? eg add a test and fix ( in another commit), but can use same pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Groupby Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants