我有一个包含以下前三列的数据集。 包括购物篮ID(唯一标识符)、销售金额(美元)和交易日期。我想为数据集的每一行计算下面的列,我想用Python来计算。在
同一篮子商品的上一次销售(如有);当前篮子的销售数量到目前为止;当前篮子(如果有)的平均到目前为止;当前篮子的最新销售(如果有)
Basket Sale Date PrevSale SaleCount MeanToDate MaxToDate
88 $15 3/01/2012 1
88 $30 11/02/2012 $15 2 $23 $30
88 $16 16/08/2012 $30 3 $20 $30
123 $90 18/06/2012 1
477 $77 19/08/2012 1
477 $57 11/12/2012 $77 2 $67 $77
566 $90 6/07/2012 1
我对Python还很陌生,我真的很难找到任何一种奇特的方法来实现它。我已经按BasketID和Date对数据进行了排序(如上所述),因此我可以通过将每个篮子向前移动一个来批量获得以前的销售额。除了循环之外,不知道如何以有效的方式获取MeanToDate和MaxToDate。。。有什么想法吗?在
这应该可以做到:
您可以阅读有关分组/聚合here的更多信息。在
相关问题 更多 >
编程相关推荐