Skip to content

Commit b7abef4

Browse files
bkandel-picwelljreback
authored andcommitted
DOC: Added example of using OrderedDict for agg.
closes #12879 Author: Ben Kandel <[email protected]> Closes #13938 from bkandel/ordered_dict_example and squashes the following commits: 8097de8 [Ben Kandel] Changed to note. 0676294 [Ben Kandel] DOC: Added example of using OrderedDict for agg.
1 parent 81819b7 commit b7abef4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

doc/source/groupby.rst

+12
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,17 @@ must be either implemented on GroupBy or available via :ref:`dispatching
487488
488489
grouped.agg({'C' : 'sum', 'D' : 'std'})
489490
491+
.. note::
492+
493+
If you pass a dict to ``aggregate``, the ordering of the output colums is
494+
non-deterministic. If you want to be sure the output columns will be in a specific
495+
order, you can use an ``OrderedDict``. Compare the output of the following two commands:
496+
497+
.. ipython:: python
498+
499+
grouped.agg({'D': 'std', 'C': 'mean'})
500+
grouped.agg(OrderedDict([('D', 'std'), ('C', 'mean')]))
501+
490502
.. _groupby.aggregate.cython:
491503

492504
Cython-optimized aggregation functions

0 commit comments

Comments
 (0)