Check the docstring (if you're using IPython, it's just df.groupby?<enter>
)
Group series using mapper (dict or key function, apply given function
to group, return result as series) or by a series of columns
Parameters
----------
by : mapping function / list of functions, dict, Series, or tuple /
list of column names.
Called on each element of the object index to determine the groups.
If a dict or Series is passed, the Series or dict VALUES will be
used to determine the groups
axis : int, default 0
level : int, level name, or sequence of such, default None
If the axis is a MultiIndex (hierarchical), group by a particular
level or levels
...
You want the level
argument:
In [20]: df.groupby(level=0).count()
Out[20]:
col1 col2
row1 1 1
row2 2 2
row4 1 1
[3 rows x 2 columns]