@@ -344,8 +344,9 @@ Aggregation
344
344
-----------
345
345
346
346
Once the GroupBy object has been created, several methods are available to
347
- perform a computation on the grouped data. An obvious one is aggregation via
348
- the ``aggregate `` or equivalently ``agg `` method:
347
+ perform a computation on the grouped data.
348
+
349
+ An obvious one is aggregation via the ``aggregate `` or equivalently ``agg `` method:
349
350
350
351
.. ipython :: python
351
352
@@ -382,6 +383,17 @@ index are the group names and whose values are the sizes of each group.
382
383
383
384
grouped.size()
384
385
386
+ .. ipython :: python
387
+
388
+ grouped.describe()
389
+
390
+ .. note ::
391
+
392
+ Aggregation functions will **not ** return the groups that you are aggregating over
393
+ if they are named *columns *. The grouped columns will be the **indices ** of the returned object.
394
+ Aggregating functions are ones that reduce the dimension of the returned objects,
395
+ for example: ``mean, sum, size, count, std, var, describe, first, last, min, max ``. This is
396
+ very much like performing a redcing operation on a ``DataFrame `` and getting a ``Series `` back.
385
397
386
398
.. _groupby.aggregate.multifunc :
387
399
@@ -537,6 +549,15 @@ and that the transformed data contains no NAs.
537
549
grouped_trans.count() # counts after transformation
538
550
grouped_trans.size() # Verify non-NA count equals group size
539
551
552
+ .. note ::
553
+
554
+ Some functions when applied to a groupby object will automatically transform the input, returning
555
+ an object of the same shape as the original. For example: ``fillna, ffill, bfill, shift ``.
556
+
557
+ .. ipython :: python
558
+
559
+ grouped.ffill()
560
+
540
561
.. _groupby.filter :
541
562
542
563
Filtration
@@ -579,6 +600,17 @@ For dataframes with multiple columns, filters should explicitly specify a column
579
600
dff[' C' ] = np.arange(8 )
580
601
dff.groupby(' B' ).filter(lambda x : len (x[' C' ]) > 2 )
581
602
603
+ .. note ::
604
+
605
+ Some functions when applied to a groupby object will act as a **filter ** on the input, returning
606
+ a reduced shape of the original (and potentitally eliminating groups), but with the index unchanged.
607
+ For example: ``head, tail nth ``.
608
+
609
+ .. ipython :: python
610
+
611
+ dff.groupby(' B' ).head(2 )
612
+
613
+
582
614
.. _groupby.dispatch :
583
615
584
616
Dispatching to instance methods
@@ -664,6 +696,12 @@ The dimension of the returned result can also change:
664
696
s.apply(f)
665
697
666
698
699
+ .. note ::
700
+
701
+ ``apply `` can act as a reducer, transformer, *or * filter function, depending on exactly what is passed to apply.
702
+ So depending on the path taken, and exactly what you are grouping. Thus the grouped columns(s) may be included in
703
+ the output as well as set the indices.
704
+
667
705
.. warning ::
668
706
669
707
In the current implementation apply calls func twice on the
0 commit comments