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.
466
-
This provides a useful syntax for constructing multiple (potentially different) aggregations for a groupby.
464
+
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
467
468
-
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
469
-
meaning that passing a dictionary to a grouped ``DataFrame``, which accepts column-to-aggregations.
470
-
2) We are deprecating passing a dict-of-dict to a grouped ``DataFrame`` in a similar manner.
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' functionarility.
471
470
472
-
Here's an example of 1), passing a dict to a grouped ``Series``:
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-dict to a grouped/rolled/resampled ``DataFrame`` in a similar manner.
475
+
476
+
This is an illustrative example:
473
477
474
478
.. ipython:: python
475
479
476
480
df = pd.DataFrame({'A': [1, 1, 1, 2, 2],
477
481
'B': range(5),
478
-
'C':range(5)})
482
+
'C':range(5)})
479
483
df
480
484
481
-
Aggregating a DataFrame with column selection.
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.
482
488
483
489
.. ipython:: python
484
490
485
491
df.groupby('A').agg({'B': ['sum', 'max'],
486
492
'C': ['count', 'min']})
487
493
488
494
489
-
We are deprecating the following
495
+
Here's an example of the first deprecation (1), passing a dict to a grouped ``Series``. This
496
+
is a combination aggregation & renaming:
490
497
491
-
.. code-block:: ipython. Which is a combination aggregation & renaming.
498
+
.. code-block:: ipython
492
499
493
500
In [6]: df.groupby('A').B.agg({'foo': 'count'})
494
501
FutureWarning: using a dictionary on a Series for aggregation
@@ -507,7 +514,7 @@ You can accomplish the same operation, more idiomatically by:
0 commit comments