我有 2 个数据框。一个用于Invoice Data,另一个用于Promotion Dates。
Invoice Data数据框
+------------+-------------+---------------+
| LocationNo | InvoiceDate | InvoiceAmount |
+------------+-------------+---------------+
| A | 01-Jul-20 | 79 |
+------------+-------------+---------------+
| B | 01-Jul-20 | 72 |
+------------+-------------+---------------+
| C | 01-Jul-20 | 24 |
+------------+-------------+---------------+
| A | 02-Jul-20 | 68 |
+------------+-------------+---------------+
| B | 02-Jul-20 | 6 |
+------------+-------------+---------------+
| C | 02-Jul-20 | 27 |
+------------+-------------+---------------+
| A | 03-Jul-20 | 25 |
+------------+-------------+---------------+
| B | 03-Jul-20 | 62 |
+------------+-------------+---------------+
| C | 03-Jul-20 | 58 |
+------------+-------------+---------------+
| D | 03-Jul-20 | 36 |
+------------+-------------+---------------+
| E | 03-Jul-20 | 65 |
+------------+-------------+---------------+
| F | 03-Jul-20 | 81 |
+------------+-------------+---------------+
df_1 = pd.DataFrame({
'LocationNo':['A','B','C','A','B','C','A','B','C','D','E','F'],
'InvoiceDate':['01-Jul-20','01-Jul-20','01-Jul-20','02-Jul-20','02-Jul-20','02-Jul-20',
'03-Jul-20','03-Jul-20','03-Jul-20','03-Jul-20','03-Jul-20','03-Jul-20'],
'InvoiceAmount':[79,72,24,68,6,27,25,62,58,36,65,81]
})
我的任务是根据两个条件合并两个数据帧,并在 满足这些条件时Yes
向新列添加值。Promotion
条件如下
LocationNo
应该匹配
应该InvoiceDate
位于各自的LocationNo
和PromotionStart
之间PromotionEnd
。
基本上,仅在和日期InvoiceDate
之间进行合并。PromotionStart
PromotionEnd
缥缈止盈
相关分类