Skip to content

Commit 0676294

Browse files
DOC: Added example of using OrderedDict for agg.
1 parent 3186fef commit 0676294

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

doc/source/groupby.rst

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
matplotlib.style.use('ggplot')
1414
import matplotlib.pyplot as plt
1515
plt.close('all')
16+
from collections import OrderedDict
1617
1718
*****************************
1819
Group By: split-apply-combine
@@ -487,6 +488,15 @@ must be either implemented on GroupBy or available via :ref:`dispatching
487488
488489
grouped.agg({'C' : 'sum', 'D' : 'std'})
489490
491+
Note that if you pass a dict to ``aggregate``, the ordering of the output colums is
492+
non-deterministic. If you want to be sure the output columns will be in a specific
493+
order, you can use an ``OrderedDict``. Compare the output of the following two commands:
494+
495+
.. ipython:: python
496+
497+
grouped.agg({'D': 'std', 'C': 'mean'})
498+
grouped.agg(OrderedDict([('D', 'std'), ('C', 'mean')]))
499+
490500
.. _groupby.aggregate.cython:
491501

492502
Cython-optimized aggregation functions

0 commit comments

Comments
 (0)