我正在尝试使用 pandas 的 NamedAgg 函数,但遇到了困难。 我收到“模块‘pandas’没有属性‘NamedAgg’”错误消息。
我正在使用文档中的示例,复制并粘贴,所以我不知道我做错了什么。有什么建议吗?
最佳答案
您必须升级到 pandas 0.25+
,Groupby aggregation with relabeling或 named aggregation :
New in version 0.25.0.
To support column-specific aggregation with control over the output column names, pandas accepts the special syntax in GroupBy.agg(), known as "named aggregation", where
- The keywords are the output column names
- The values are tuples whose first element is the column to select and the second element is the aggregation to apply to that column. Pandas provides the pandas.NamedAgg namedtuple with the fields ['column', 'aggfunc'] to make it clearer what the arguments are. As usual, the aggregation can be a callable or a string alias.
关于python - Pandas NamedAgg 错误 : module 'pandas' has no attribute 'NamedAgg' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58264105/