You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ``.groupby(..).agg(..)``, ``.rolling(..).agg(..)``, and ``.resample(..).agg(..)`` syntax can accept a variable of inputs, including scalars,
465
+
list, and a dict of column names to scalars or lists. This provides a useful syntax for constructing multiple
466
+
(potentially different) aggregations.
467
+
468
+
However, ``.agg(..)`` can *also* accept a dict that allows 'renaming' of the result columns. This is a complicated and confusing syntax, as well as not consistent
469
+
between ``Series`` and ``DataFrame``. We are deprecating this 'renaming' functionaility.
470
+
471
+
1) We are deprecating passing a dict to a grouped/rolled/resampled ``Series``. This allowed
472
+
one to ``rename`` the resulting aggregation, but this had a completely different
473
+
meaning than passing a dictionary to a grouped ``DataFrame``, which accepts column-to-aggregations.
474
+
2) We are deprecating passing a dict-of-dicts to a grouped/rolled/resampled ``DataFrame`` in a similar manner.
475
+
476
+
This is an illustrative example:
477
+
478
+
.. ipython:: python
479
+
480
+
df = pd.DataFrame({'A': [1, 1, 1, 2, 2],
481
+
'B': range(5),
482
+
'C': range(5)})
483
+
df
484
+
485
+
Here is a typical useful syntax for computing different aggregations for different columns. This
486
+
is a natural (and useful) syntax. We aggregate from the dict-to-list by taking the specified
487
+
columns and applying the list of functions. This returns a ``MultiIndex`` for the columns.
488
+
489
+
.. ipython:: python
490
+
491
+
df.groupby('A').agg({'B': 'sum', 'C': 'min'})
492
+
493
+
Here's an example of the first deprecation (1), passing a dict to a grouped ``Series``. This
494
+
is a combination aggregation & renaming:
495
+
496
+
.. code-block:: ipython
497
+
498
+
In [6]: df.groupby('A').B.agg({'foo': 'count'})
499
+
FutureWarning: using a dict on a Series for aggregation
500
+
is deprecated and will be removed in a future version
501
+
502
+
Out[6]:
503
+
foo
504
+
A
505
+
1 3
506
+
2 2
507
+
508
+
You can accomplish the same operation, more idiomatically by:
0 commit comments