From 0676294ed272c508b1f45ae60600f441cf895249 Mon Sep 17 00:00:00 2001 From: Ben Kandel Date: Fri, 5 Aug 2016 17:04:39 -0400 Subject: [PATCH 1/2] DOC: Added example of using OrderedDict for agg. --- doc/source/groupby.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/source/groupby.rst b/doc/source/groupby.rst index c9095c3ae1a60..f4aeb3d9e00fa 100644 --- a/doc/source/groupby.rst +++ b/doc/source/groupby.rst @@ -13,6 +13,7 @@ matplotlib.style.use('ggplot') import matplotlib.pyplot as plt plt.close('all') + from collections import OrderedDict ***************************** Group By: split-apply-combine @@ -487,6 +488,15 @@ must be either implemented on GroupBy or available via :ref:`dispatching grouped.agg({'C' : 'sum', 'D' : 'std'}) +Note that if you pass a dict to ``aggregate``, the ordering of the output colums is +non-deterministic. If you want to be sure the output columns will be in a specific +order, you can use an ``OrderedDict``. Compare the output of the following two commands: + +.. ipython:: python + + grouped.agg({'D': 'std', 'C': 'mean'}) + grouped.agg(OrderedDict([('D', 'std'), ('C', 'mean')])) + .. _groupby.aggregate.cython: Cython-optimized aggregation functions From 8097de8410dbf676f7ffa693da2529bc5f991f55 Mon Sep 17 00:00:00 2001 From: Ben Kandel Date: Mon, 8 Aug 2016 12:02:04 -0400 Subject: [PATCH 2/2] Changed to note. --- doc/source/groupby.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/source/groupby.rst b/doc/source/groupby.rst index f4aeb3d9e00fa..c5a77770085d6 100644 --- a/doc/source/groupby.rst +++ b/doc/source/groupby.rst @@ -488,9 +488,11 @@ must be either implemented on GroupBy or available via :ref:`dispatching grouped.agg({'C' : 'sum', 'D' : 'std'}) -Note that if you pass a dict to ``aggregate``, the ordering of the output colums is -non-deterministic. If you want to be sure the output columns will be in a specific -order, you can use an ``OrderedDict``. Compare the output of the following two commands: +.. note:: + + If you pass a dict to ``aggregate``, the ordering of the output colums is + non-deterministic. If you want to be sure the output columns will be in a specific + order, you can use an ``OrderedDict``. Compare the output of the following two commands: .. ipython:: python