0

I've been struggling with the following; I have a dataframe which basically contains a set of date ranges (start date and end date) and a "period" name for these. I have another dataframe (which is more like a fact table) in which I want to add the matching "period name" from this other dataframe. Below a short example of what I'm trying to achieve

df1:

    end_date    start_date    period
0   2019-10-01  2019-07-01    1
1   2020-01-01  2019-10-01    2
2   2020-04-01  2020-01-01    3
3   2020-07-01  2020-04-01    4
4   2020-10-01  2020-07-01    5
5   2021-01-01  2020-10-01    6
6   2021-04-01  2021-01-01    7
7   2021-07-01  2021-04-01    8
8   2021-10-01  2021-07-01    9
9   2022-01-01  2021-10-01    10

df2:


        zone    closedate   
0       APAC    2011-12-09  
1       APAC    2013-01-23  
2       APAC    2013-04-10  
3       APAC    2013-06-29  
4       APAC    2013-07-18  
... ... ... ... ...
4996    EMEA    2021-12-18  
4997    EMEA    2022-01-02  
4998    EMEA    2022-01-09  
4999    EMEA    2022-01-29  
5000    EMEA    2022-04-11  

Desired output:

        zone    closedate   period
0       APAC    2019-12-09  2
1       APAC    2020-01-23  3
2       APAC    2020-04-10  4
3       APAC    2020-06-29  4
4       APAC    2020-07-18  5
... ... ... ... ...
4996    EMEA    2021-12-18  10
4997    EMEA    2021-01-02  7
4998    EMEA    2021-01-09  7
4999    EMEA    2021-01-29  7
5000    EMEA    2021-04-11  8

Would be grateful with any help in the right direction!

Caesar
  • 47
  • 8

0 Answers0