pandas.errors.SpecificationError#

exception pandas.errors.SpecificationError[源代码]#

当函数指定不当(ill-specified)时,agg 引发的异常。

此异常会在两种情况下引发。

第一种情况是在 DataFrame 或 Series 上调用 agg 并使用嵌套的重命名器(dict-of-dict)。

第二种情况是在 DataFrame 上调用 agg 并使用重复的函数名称而未分配列名。

Examples

>>> df = pd.DataFrame({'A': [1, 1, 1, 2, 2],
...                    'B': range(5),
...                    'C': range(5)})
>>> df.groupby('A').B.agg({'foo': 'count'}) 
... # SpecificationError: nested renamer is not supported
>>> df.groupby('A').agg({'B': {'foo': ['sum', 'max']}}) 
... # SpecificationError: nested renamer is not supported
>>> df.groupby('A').agg(['min', 'min']) 
... # SpecificationError: nested renamer is not supported