使用pandas制作近7天、近15天、近30天的销量和

  1. 问题描述:
  2. 1、大批量数据表,字段为:shop_name、site、sku、date、quantity
  3. 2、日期不连贯,且有有多sku对应的日期是缺失的。

方法一:pandas、切片
在这里插入图片描述

test1=order_data.reset_index()
#近7天销量和
for i in test1.index:
test1[‘purchase_date’]=pd.to_datetime(test1[‘purchase_date’],format=’%Y-%m-%d’)
qiepian = test1.loc[(((test1[‘shop_name’]==test1.loc[i][‘shop_name’]))&
((test1[‘site’]==test1.loc[i][‘site’]))&
((test1[‘sku’]==test1.loc[i][‘sku’]))&
((test1.loc[i,‘purchase_date’]-test1[‘purchase_date’]).apply(lambda x : x.days)<7)&
((test1.loc[i,‘purchase_date’]-test1[‘purchase_date’]).apply(lambda x : x.days)>-1))]
day7_sum=qiepian[‘quantity’].sum()
#print(qiepian)
#print(day7_sum)
test1.loc[i,‘day7_sum’]=day7_sum

#近15天销量和
for i in test1.index:
test1[‘purchase_date’]=pd.to_datetime(test1[‘purchase_date’],format=’%Y-%m-%d’)
qiepian = test1.loc[(((test1[‘shop_name’]==test1.loc[i][‘shop_name’]))&
((test1[‘site’]==test1.loc[i][‘site’]))&
((test1[‘sku’]==test1.loc[i][‘sku’]))&
((test1.loc[i,‘purchase_date’]-test1[‘purchase_date’]).apply(lambda x : x.days)<15)&
((test1.loc[i,‘purchase_date’]-test1[‘purchase_date’]).apply(lambda x : x.days)>-1))]
day15_sum=qiepian[‘quantity’].sum()
#print(qiepian)
#print(day7_sum)
test1.loc[i,‘day15_sum’]=day15_sum

#近30天销量和

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值