合并特定日期范围内的 Pandas DataFrame
我有 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之间进行合并。PromotionStartPromotionEnd
查看完整描述