合并特定日期范圍內(nèi)的 Pandas DataFrame
我有 2 個數(shù)據(jù)框。一個用于Invoice Data,另一個用于Promotion Dates。Invoice Data數(shù)據(jù)框+------------+-------------+---------------+| 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]})我的任務(wù)是根據(jù)兩個條件合并兩個數(shù)據(jù)幀,并在 滿足這些條件時Yes向新列添加值。Promotion條件如下LocationNo應(yīng)該匹配應(yīng)該InvoiceDate位于各自的LocationNo和PromotionStart之間PromotionEnd。基本上,僅在和日期InvoiceDate之間進(jìn)行合并。PromotionStartPromotionEnd
查看完整描述