gpt4 book ai didi

python - Pandas NamedAgg 错误 : module 'pandas' has no attribute 'NamedAgg'

转载 作者:太空宇宙 更新时间:2023-11-04 11:10:50 25 4
gpt4 key购买 nike

我正在尝试使用 pandas 的 NamedAgg 函数,但遇到了困难。我收到“模块‘pandas’没有属性‘NamedAgg’”错误消息。

我正在使用文档中的示例,复制并粘贴,所以我不知道我做错了什么。有什么建议吗?

pandas problem with NamedAgg

最佳答案

您必须升级到 pandas 0.25+Groupby aggregation with relabelingnamed 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com