【问题标题】:How can I find cumulative count within a group using Alibaba PyODPS?如何使用阿里巴巴 PyODPS 查找组内的累积计数?
【发布时间】:2019-05-21 02:54:18
【问题描述】:

让我们假设我有一个名为 Iris 的数据框,其中 name、sepallength、sepalwidth、petalwidth 和petallength 作为列。我想在一个组中找到 sepallength 的累积计数。

我的代码:

iris['name', 'sepallength', iris.groupby('name').sort('sepallength').sepallength.count()].head(5)

但它显示错误的结果,我错过了什么?

【问题讨论】:

    标签: python python-3.x alibaba-cloud


    【解决方案1】:

    cumcount代替count,前一个是窗口函数,后一个是聚合。

    iris['name', 'sepallength', iris.groupby('name').sort('sepallength').sepallength.cumcount()].head(5)
    

    【讨论】:

      猜你喜欢
      • 2021-03-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-28
      • 2020-01-13
      • 2019-12-10
      • 2020-06-14
      • 2019-07-04
      • 1970-01-01
      相关资源
      最近更新 更多