In pandas groupby, I gave the argument of agg () in dict format to apply multiple functions to one column, but since that function was deleted in v1, it can no longer be used. The solution. The data is based on the pandas documentation.
animals = pd.DataFrame({'kind': ['cat', 'dog', 'cat', 'dog'],
'height': [9.1, 6.0, 9.5, 34.0],
'weight': [7.9, 7.5, 9.9, 198.0]})
#For each kind, total the total value of height and the number of cases, and each"sum_all", "count_all"Name it
animals.groupby("kind")["height"].agg({"sum_all":"sum", "count_all":"count"})
--Expected output (it was possible before v1)
--Actual output
SpecificationError: nested renamer is not supported
--There was a description in whats new of the document - https://pandas.pydata.org/pandas-docs/stable/whatsnew/v1.0.0.html --It seems to be nested renaming, but it seems that this has disappeared
Removed support for nested renaming in DataFrame.aggregate(), Series.aggregate(), core.groupby.DataFrameGroupBy.aggregate(), core.groupby.SeriesGroupBy.aggregate(), core.window.rolling.Rolling.aggregate() (GH18529)
――As described below, it seems that aggregation and rename cannot be performed for one column at the same time. - https://pandas.pydata.org/pandas-docs/stable/whatsnew/v0.20.0.html#whatsnew-0200-api-breaking-deprecate-group-agg-dict
--The problem is that you are summarizing and renaming at the same time, so you can separate them.
animals.groupby("kind")["height"].agg(["sum", "count"])
.rename(columns={"sum": "sum_all",
"count":"count_all"})
-Use Named Aggrecation (feature from v0.25)
animals.groupby("kind")["height"].agg(sum_all="sum",
count_all="count")
-(Reference) Named Aggrecation without columns will be written as follows ――This way of writing is easy to understand because you can specify which variable to aggregate.
animals.groupby("kind").agg(sum_all=("height", "sum"),
count_all=("height", "count"))