當(dāng)前位置:
首頁 >
DataFrame groupby+agg出现SpecificationError: nested renamer is not supported的错误
發(fā)布時(shí)間:2023/12/29
42
豆豆
生活随笔
收集整理的這篇文章主要介紹了
DataFrame groupby+agg出现SpecificationError: nested renamer is not supported的错误
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
這個(gè)應(yīng)該是pandas的版本問題 ,我的是v1.0.5,也會(huì)出現(xiàn)這個(gè)問題,如下面的代碼所示:
>>> import pandas as pd >>> data=pd.DataFrame({'name':['x','y','x','y','z'],'sex':['f','m','f','f','m'],'age':[25,26,45,67,30]}) >>> dataname sex age 0 x f 25 1 y m 26 2 x f 45 3 y f 67 4 z m 30 >>> data.groupby('name')['age'].agg({'sums':'sum'}) Traceback (most recent call last):File "<stdin>", line 1, in <module>File "/Applications/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/generic.py", line 253, in aggregateret = self._aggregate_multiple_funcs(func)File "/Applications/anaconda3/lib/python3.6/site-packages/pandas/core/groupby/generic.py", line 294, in _aggregate_multiple_funcsraise SpecificationError("nested renamer is not supported") pandas.core.base.SpecificationError: nested renamer is not supported將代碼改成下面的方式就可以了
- 根據(jù)單列聚合后進(jìn)行單個(gè)計(jì)算
- 根據(jù)單列聚合后進(jìn)行多個(gè)計(jì)算?
- 根據(jù)多列聚合后進(jìn)行多個(gè)計(jì)算
?
總結(jié)
以上是生活随笔為你收集整理的DataFrame groupby+agg出现SpecificationError: nested renamer is not supported的错误的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。