retrun a Series
, to get row counts per group is by calling .size()
:
df.groupby(['col_name']).size()
retrun a DataFrame
(instead of a Series
) :
df.groupby(['col_name']).size().reset_index(name='counts')
Ref: stackoverflow: Get statistics for each group (such as count, mean, etc) using pandas GroupBy?