Skip to content

Commit e243f18

Browse files
committed
API: add doc examples for #9052
1 parent 750556b commit e243f18

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

doc/source/whatsnew/v0.18.0.txt

+57
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,63 @@ New API
517517

518518
In the new API, you can either downsample OR upsample. The prior implementation would allow you to pass an aggregator function (like ``mean``) even though you were upsampling, providing a bit of confusion.
519519

520+
.. _whatsnew_0180.breaking.aggregation:
521+
522+
Aggregation API clarifictions
523+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
524+
525+
As part of the new API for :ref:`window functions <whatsnew_0180.enhancements.moments>` and :ref:`resampling <whatsnew_0180.resample>`, aggregation functions have been
526+
clarified. (:issue:`9052`). A full set of examples are presented in :ref:`groupby <groupby.aggregation>`.
527+
528+
Here are the available methodologies and changes for these aggregations.
529+
530+
.. ipython:: python
531+
532+
df = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
533+
'foo', 'bar', 'foo', 'foo'],
534+
'B': ['one', 'one', 'two', 'three',
535+
'two', 'two', 'one', 'three'],
536+
'C': np.random.randn(8),
537+
'D': np.arange(8)})
538+
539+
grouped = df.groupby(['A', 'B'])
540+
541+
Passing a single function or a list of aggregation functions
542+
543+
.. ipython:: python
544+
545+
grouped[['D','C']].agg(['sum','mean'])
546+
547+
548+
Passing a single level dictionary will perform aggregations and name
549+
the result columns as the keys.
550+
551+
.. ipython:: python
552+
553+
grouped['D'].agg({'result1': np.sum,
554+
'result2': np.mean})
555+
556+
You can also pass a single level dictionary where the keys are the column names.
557+
558+
.. ipython:: python
559+
560+
grouped.agg({'C': 'sum', 'D': 'std'})
561+
562+
Finally you can pass a nested dictionary to enable specific functions on specific
563+
columns and have renaming.
564+
565+
.. ipython:: python
566+
567+
grouped.agg({'C': {'summer': 'sum'}, 'D' : {'stddev':'std'}})
568+
569+
The change in 0.18.0 is to disallow the following, which could be ambiguous,
570+
and will now raise a ``SpecificationError``.
571+
572+
.. code-block:: python
573+
574+
grouped.agg({'summer': {'C': 'sum'}, 'stddev' : {'D':'std'}})
575+
576+
520577
Changes to eval
521578
^^^^^^^^^^^^^^^
522579

0 commit comments

Comments
 (0)