wesm/pandas — Issue #610: Add ability to maintain order of groupby results when passing multiple functions
Author: wesm
Created: 2012-01-11 20:42:35+00:00
State: open
Labels: Enhancement

from @stig

I'd love an option to maintain the column order that I've specified. At the moment I do this:

```
print df.groupby('Status')['Duration'].agg({ 'Min': np.min,
'Max':np.max,
'Mean': np.mean,
'Median': np.median,
'Stddev':np.std,
})
```
but the column order come out like this:

```
Max Mean Median Min Stddev
Error 0.141 0.09967 0.093 0.072 0.02796
Success 12.07 5.879 11.05 0.27 5.41
```

Which is not ideal. I'd love to pass an OrderedDict and have the order be respected.

```
d = OrderedDict([('Min', np.min),
('Max', np.max),
('Mean', np.mean),
('Median', np.median),
('Stddev', np.std),
])
```

... or, the method could just accept a list of tuples and respect that order.