[Pandas-dev] Deprecation of using a dict in groupby().agg({...}) to rename resulting columns

Joris Van den Bossche jorisvandenbossche at gmail.com
Wed Apr 12 09:20:52 EDT 2017


Hi all,

As a heads up, we are deprecating the use of a dictionary in the agg method
on groupby/resample/rolling objects.

Basic example:

In [1]: df = pd.DataFrame({'A': [1, 1, 1, 2, 2],
   ...:                    'B': range(5),
   ...:                    'C':range(5)})

In [3]: df.groupby('A').B.agg({'foo': 'count'})
Out[3]:
   foo
A
1    3
2    2

The above will be deprecated (and removed in a future version).

The documentation added in https://github.com/pandas-dev/pandas/pull/15931
gives a more detailed explanation of the reasoning, but basically it is to
clean up the API: now you can use dicts both to specify a aggregation
function for a specific column (for dataframes) as to rename the result
(series, or dataframes with nested dict), which is a confusing double use
of dicts.

The PR will be merged shortly, but the 0.20 release is still a few weeks
off, so certainly still time to give feedback. Which is certainly welcome!

Regards,
Joris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pandas-dev/attachments/20170412/781effcf/attachment.html>


More information about the Pandas-dev mailing list