我有一些消费者购买数据
CustomerID InvoiceDate
13654.0 2011-07-17 13:29:00
14841.0 2010-12-16 10:28:00
19543.0 2011-10-18 16:58:00
12877.0 2011-06-15 13:34:00
15073.0 2011-06-06 12:33:00
我对顾客的购买率很感兴趣。我想按每个客户分组,然后确定每个季度的购买量(假设从1月份开始,每个季度每3个月一次)。你知道吗
我可以定义每个季度的开始和结束时间,再做一个专栏。我想知道我是否可以用groupby
来实现同样的目标。你知道吗
目前,我是这样做的:
r = data.groupby('CustomerID')
frames = []
for name,frame in r:
f =frame.set_index('InvoiceDate').resample("QS").count()
f['CustomerID']= name
frames.append(f)
g = pd.concat(frames)
我想这是我能做的最好的:
更新:
这就是你想要的吗?你知道吗
相关问题 更多 >
编程相关推荐