【发布时间】:2020-02-20 14:02:25
【问题描述】:
我有两个数据框。第一个看起来像这样:
id, orderdate, orderid, amount,camp1, camp2, camp3
1 2020-01-01 100 100 1 0 0
2 2020-02-01 120 200 1 0 1
3 2019-12-01 130 500 0 1 0
4 2019-11-01 150 750 0 1 0
5 2020-01-01 160 1000 1 1 1
camp1, camp2, camp3 部分显示客户是否参加了活动。
并且广告系列有一个时期字典,这样
camp_periods = {'camp1':
[datetime.strptime('2019-04-08', '%Y-%m-%d'), datetime.strptime('2019-06-06', '%Y-%m-%d')],
'camp2':
[datetime.strptime('2019-09-15', '%Y-%m-%d'), datetime.strptime('2019-09-28', '%Y-%m-%d')],
'camp3':
[datetime.strptime('2019-11-15', '%Y-%m-%d'), datetime.strptime('2019-12-28', '%Y-%m-%d')]
}
如果orderdate 在camp_periods 字典中的活动期间之间,并且如果客户参加了该活动,我想创建一个表格,给出每个客户的订单数量和order amounts 总数。
【问题讨论】:
标签: python pandas dataframe dictionary