python dataframe - 遍历数据帧以查找未来日期,考虑之前的迭代

python dataframe - iterate through dataframes to find future date, considering previous iterations

半年以来,我一直在 python 和所有令人难以置信的库中,例如 Panads Dataframes。

我正在努力在我的代码中实现迭代逻辑(见附图)。逻辑对我来说很清楚,但不幸的是我无法对代码段进行编码!

不知道有没有人出来,谁能给我正确的提示?

非常感谢您!

Transparent iteration logic

df1 = pd.to_datetime(['01.01.2020', '15.01.2020', '01.02.2020', '01.03.2020', '15.03.2020', '01.04.2020', '01.05.2020', '01.06.2020', '01.07.2020', '01.08.2020', '01.09.2020', '01.10.2020'])
df2 = pd.to_datetime(['01.01.2020', '14.01.2020', '04.03.2020', '20.03.2020', '17.07.2020', '19.09.2020'])
import pandas as pd
df1 = pd.to_datetime(['01.01.2020', '15.01.2020', '01.02.2020', '01.03.2020', '15.03.2020', '01.04.2020', '01.05.2020', '01.06.2020', '01.07.2020', '01.08.2020', '01.09.2020', '01.10.2020'], format="%d.%m.%Y")
df2 = pd.to_datetime(['01.01.2020', '14.01.2020', '04.03.2020', '20.03.2020', '17.07.2020', '19.09.2020', '03.11.2021'], format="%d.%m.%Y")


lst_df1 = list(df1.sort_values())
lst_df2 = list(df2.sort_values())

dict_df3 = {} 
 
window_start = lst_df2[0]
window_stop = lst_df2[1]
for date in lst_df1:
    while date > window_stop:
            window_start = lst_df2[0]
            lst_df2 = lst_df2[1:]
            window_stop = lst_df2[0]
            
    dict_df3[date] = window_start

df3 = pd.DataFrame.from_dict(dict_df3, orient='index').reset_index()