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.
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.
471
+
472
+
Here's an example of 1), passing a dict to a grouped ``Series``:
473
+
474
+
.. ipython:: python
475
+
476
+
df = pd.DataFrame({'A': [1, 1, 1, 2, 2],
477
+
'B': range(5),
478
+
'C':range(5)})
479
+
df
480
+
481
+
Aggregating a DataFrame with column selection.
482
+
483
+
.. ipython:: python
484
+
485
+
df.groupby('A').agg({'B': ['sum', 'max'],
486
+
'C': ['count', 'min']})
487
+
488
+
489
+
We are deprecating the following
490
+
491
+
.. code-block:: ipython. Which is a combination aggregation & renaming.
492
+
493
+
In [6]: df.groupby('A').B.agg({'foo': 'count'})
494
+
FutureWarning: using a dictionary on a Series for aggregation
495
+
is deprecated and will be removed in a future version
496
+
497
+
Out[6]:
498
+
foo
499
+
A
500
+
1 3
501
+
2 2
502
+
503
+
You can accomplish the same operation, more idiomatically by:
0 commit comments