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.
432
+
This provides a useful syntax for constructing multiple (potentially different) aggregations for a groupby.
433
+
434
+
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
435
+
meaning that passing a dictionary to a grouped ``DataFrame``, which accepts column-to-aggregations.
436
+
2) We are deprecating passing a dict-of-dict to a grouped ``DataFrame`` in a similar manner.
437
+
438
+
Here's an example of 1), passing a dict to a grouped ``Series``:
439
+
440
+
.. ipython:: python
441
+
442
+
df = pd.DataFrame({'A': [1, 1, 1, 2, 2],
443
+
'B': range(5),
444
+
'C':range(5)})
445
+
df
446
+
447
+
Aggregating a DataFrame with column selection.
448
+
449
+
.. ipython:: python
450
+
451
+
df.groupby('A').agg({'B': ['sum', 'max'],
452
+
'C': ['count', 'min']})
453
+
454
+
455
+
We are deprecating the following
456
+
457
+
.. code-block:: ipython. Which is a combination aggregation & renaming.
458
+
459
+
In [6]: df.groupby('A').B.agg({'foo': 'count'})
460
+
FutureWarning: using a dictionary on a Series for aggregation
461
+
is deprecated and will be removed in a future version
462
+
463
+
Out[6]:
464
+
foo
465
+
A
466
+
1 3
467
+
2 2
468
+
469
+
You can accomplish the same operation, more idiomatically by:
0 commit comments