Skip to content

Commit

Permalink
DOC: one line example for GroupBy.size()
Browse files Browse the repository at this point in the history
  • Loading branch information
Chang She committed May 3, 2012
1 parent 1403700 commit d96113a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/source/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ the ``aggregate`` or equivalently ``agg`` method:
grouped = df.groupby(['A', 'B'])
grouped.aggregate(np.sum)
Another simple example is to compute the size of each group. This is included
in GroupBy as the ``size`` method. It returns a Series whose index are the
group names and whose values are the sizes of each group.

.. ipython:: python
grouped.size()
As you can see, the result of the aggregation will have the group names as the
new index along the grouped axis. In the case of multiple keys, the result is a
:ref:`MultiIndex <indexing.hierarchical>` by default, though this can be
Expand All @@ -302,6 +310,7 @@ same result as the column names are stored in the resulting ``MultiIndex``:
df.groupby(['A', 'B']).sum().reset_index()
.. _groupby.aggregate.multifunc:

Applying multiple functions at once
Expand Down

0 comments on commit d96113a

Please sign in to comment.