I would like to merge two dataframes based on the condition of a item sold falls between a date range, matches the price, and matches the item id. Non-matches need to be kept as well, and marked as a non-event.
Sales data:
Date ID Price
1/1/2020 3 9.99
1/1/2020 4 5.99
1/2/2020 10 69.99
1/10/2020 4 5.99
1/11/2020 3 10.99
Promotional data:
Start_Date End_Date ID Price Promo
1/1/2020 1/8/2020 3 9.99 Event1
1/1/2020 1/8/2020 4 5.99 Event1
1/1/2020 1/8/2020 10 49.99 Event1
Desired result:
Date ID Price Promo
1/1/2020 3 9.99 Event1
1/1/2020 4 5.99 Event1
1/2/2020 10 69.99 Non-Event
1/10/2020 4 5.99 Non-Event
1/11/2020 3 10.99 Non-Event
I have been stuck on this for quite some time. I've tried a few different methods including merge_asof
, numpy.piecewise
, and pandasql
, but this seems to be a bit above my skill ceiling currently. Any help is greatly appreciated.