The fall through value_counts (for Series) is a bit strange, I think better result would be (with the standard options):
Can put together if people think it's good.
In [132]: df = pd.DataFrame([['a_link', 'dofollow'], ['a_link', 'dofollow'], ['a_link', 'nofollow'], ['b_link', 'javascript']], columns=['link', 'type'])
In [133]: g = df.groupby(['link', 'type'])
In [134]: g.value_counts()
AttributeError: 'DataFrameGroupBy' object has no attribute 'value_counts'
In [135]: g.link.value_counts() # redundant level
Out[135]:
link type
a_link dofollow a_link 2
nofollow a_link 1
b_link javascript b_link 1
dtype: int64
Following would make sense for DataFrameGroupby to:
In [136]: pd.Series([len(g.groups[i]) for i in g.grouper.result_index], g.grouper.result_index)
Out[136]:
link type
a_link dofollow 2
nofollow 1
b_link javascript 1
dtype: int64
Note: as_index doesn't make sense here so would be ignored.
Comment From: hayd
Ahem, that would be size....
Comment From: hayd
Maybe it should be size with standard value_count options ?
Comment From: jreback
maybe just alias value_counts
to size
?
this related (maybe dupe) of #6312
Comment From: hayd
Yeah I think this makes sense, I don't think most people want to do anything else (trying to think of a case when this wouldn't be desired)... I guess that's when the selected column isn't in the index... darn then it is going to be different. :s
Comment From: rhshadrach
In the result of a groupby, the groups are the index, not the values. To me, this makes "g.value_counts()" a bit confusing. Since g.size() already gives the desired output, I personally think this should not be implemented/aliased.