【问题标题】:Can't aggregate with min and max in pandas无法在 pandas 中聚合 min 和 max
【发布时间】:2021-10-19 20:20:56
【问题描述】:

所以当我在聚合一切时使用 sum 函数时:

data_update = data_update.groupby([data_update['day_time'].dt.month, data_update['day_time'].dt.year]).agg('sum')

但是当我使用 min 我得到这个错误:

data_update = data_update.groupby([data_update['day_time'].dt.month, data_update['day_time'].dt.year]).agg('min')

ValueError: 传递的项目数错误 1,放置意味着 20

【问题讨论】:

  • 也许...).agg('min')try ...)['day_time'].agg('min')
  • 如果我使用它,我不会得到最小日期吗?
  • 你能提供样本数据吗?
  • 不幸的是,数据是私有的,但发现了问题

标签: python pandas dataframe


【解决方案1】:

原来将 pandas 从 1.1.2 升级到 1.3.2 解决了这个问题,并给了我这个警告,这没问题,而且完全有意义:

 FutureWarning: Dropping invalid columns in DataFrameGroupBy.min is deprecated. In a future version, a TypeError will be raised. Before calling .min, select only columns which should be valid for the function.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    • 2019-09-21
    • 2013-07-18
    • 2017-10-29
    • 2023-03-19
    • 2018-01-24
    • 1970-01-01
    相关资源
    最近更新 更多