pandas.errors.SpecificationError: nested renamer is not supported报错

在使用gropuby+agg分组的时候报错

报错代码

segStat = segmentDataFrame.groupby(
            by="segment"
        )["segment"].agg({
            "计数":numpy.size
        }).reset_index()

报错信息

Traceback (most recent call last):
  File "XXX\2.3.py", line 53, in <module>
    )["segment"].agg({
  File "D:\program\Python\lib\site-packages\pandas\core\groupby\generic.py", line 281, in aggregate
    ret = self._aggregate_multiple_funcs(func)
  File "D:\program\Python\lib\site-packages\pandas\core\groupby\generic.py", line 317, in _aggregate_multiple_funcs
    raise SpecificationError("nested renamer is not supported")
pandas.errors.SpecificationError: nested renamer is not supported

分析
pandas在 1.0版本后,更新了API写法,原有的gropuby+agg分组+聚合函数写法有变更

修改后的写法

segStat = segmentDataFrame.groupby(
    ["segment"]
    )["segment"].agg(
    [("计数",numpy.size)]
    ).reset_index()

你可能感兴趣的:(python,pandas,python,数据分析)