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

标签 python pandas pandas-groupby

我正在尝试使用 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/

相关文章:

python - 我应该如何存储来自 Pyramid 应用程序的登录信息?烧杯?

python - 如何在 DataFrame 中的字符串中添加换行符?

Python创建列表字典

python - 如何在 Pandas 中创建按索引分组的记录列表?

python - Pandas:在条件后创建指示列

python - 最小化温度向量中每个 T 值的多变量函数

python - 通过value_counts()将一个dataframe分成两个DF

python - Pandas Dataframe 输出到 JSON

python - 如何删除 Pandas 组中的重复项

python - 使用pandas将具有匹配索引的多行动态转换为多列