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(..)`` syntax can accept a variable of inputs, including scalars, list, and a dictionary of column names to scalars or lists.
465
-
This provides a useful syntax for constructing multiple (potentially different) aggregations for a groupby.
463
+
The ``.groupby(..).agg(..)``, ``.rolling(..).agg(..)``, and ``.resample(..).agg(..)`` syntax can accept a variable of inputs, including scalars,
464
+
list, and a dict of column names to scalars or lists. This provides a useful syntax for constructing multiple
465
+
(potentially different) aggregations.
466
466
467
-
1) We are deprecating passing a dictionary to a grouped ``Series``. This allowed one to ``rename`` the resulting aggregation, but this had a completely different
468
-
meaning that passing a dictionary to a grouped ``DataFrame``, which accepts column-to-aggregations.
469
-
2) We are deprecating passing a dict-of-dict to a grouped ``DataFrame`` in a similar manner.
467
+
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
468
+
between ``Series`` and ``DataFrame``. We are deprecating this 'renaming' functionarility.
470
469
471
-
Here's an example of 1), passing a dict to a grouped ``Series``:
470
+
1) We are deprecating passing a dict to a grouped/rolled/resampled ``Series``. This allowed
471
+
one to ``rename`` the resulting aggregation, but this had a completely different
472
+
meaning than passing a dictionary to a grouped ``DataFrame``, which accepts column-to-aggregations.
473
+
2) We are deprecating passing a dict-of-dict to a grouped/rolled/resampled ``DataFrame`` in a similar manner.
474
+
475
+
This is an illustrative example:
472
476
473
477
.. ipython:: python
474
478
475
479
df = pd.DataFrame({'A': [1, 1, 1, 2, 2],
476
480
'B': range(5),
477
-
'C':range(5)})
481
+
'C':range(5)})
478
482
df
479
483
480
-
Aggregating a DataFrame with column selection.
484
+
Here is a typical useful syntax for computing different aggregations for different columns. This
485
+
is a natural (and useful) syntax. We aggregate from the dict-to-list by taking the specified
486
+
columns and applying the list of functions. This returns a ``MultiIndex`` for the columns.
481
487
482
488
.. ipython:: python
483
489
484
490
df.groupby('A').agg({'B': ['sum', 'max'],
485
491
'C': ['count', 'min']})
486
492
487
493
488
-
We are deprecating the following
494
+
Here's an example of the first deprecation (1), passing a dict to a grouped ``Series``. This
495
+
is a combination aggregation & renaming:
489
496
490
-
.. code-block:: ipython. Which is a combination aggregation & renaming.
497
+
.. code-block:: ipython
491
498
492
499
In [6]: df.groupby('A').B.agg({'foo': 'count'})
493
500
FutureWarning: using a dictionary on a Series for aggregation
@@ -506,7 +513,7 @@ You can accomplish the same operation, more idiomatically by:
0 commit comments