Question: df1 is like below,  A time 0 32 2023-09-30 08:00:00 1 18 2023-09-30 08:01:00 2 61 2023-09-30 08:02:00 3 87 2023-09-30 08:03:00 4 46 2023-09-30 08:04:00 5 18 2023-09-30 08:05:00 6 65 2023-09-30 08:06:00 7 18 2023-09-30 08:07:00 8 10 2023-09-30 08:08:00 9 93 2023-09-30 08:09:00  and df2 is like below,  AA BB Timestamp 0 27 54 2023-10-03 11:57:57.898397 1 28 56 2023-10-03 11:57:59.398397 2 29 58 2023-10-03 11:58:00.898397 3 30 60 2023-10-03 11:58:02.398397 4 31 62 2023-10-03 11:58:03.898397 5 32 64 2023-10-03 11:58:05.398397 6 33 66 2023-10-03 11:58:06.898397 7 34 68 2023-10-03 11:58:08.398397 8 35 70 2023-10-03 11:59:04.398397  I want to add the A data from df1 to df2 in a new column called CC. I will provide a lower and upper bound for the df1 data to consider. Since df1 has 7 minutes of data and df2 has 2 minutes of data, I will specify a datetime range say 2023-09-30 08:02:00 to 2023-09-30 08:08:00. I want to start adding the 'A' data from df1 to df2 starting from the lower bound, and continue adding 'A' data until df2 is filled. If 1 minute is completed in df2, I want to move on to the next entry in df1, this is how I want to fill CC. The out put should look like this,  AA BB Timestamp CC 0 27 54 2023-10-03 11:57:57.898397 61 1 28 56 2023-10-03 11:57:59.398397 61 2 29 58 2023-10-03 11:58:00.898397 87 3 30 60 2023-10-03 11:58:02.398397 87 4 31 62 2023-10-03 11:58:12.898397 87 5 32 64 2023-10-03 11:58:24.398397 87 6 33 66 2023-10-03 11:58:40.898397 87 7 34 68 2023-10-03 11:58:52.398397 87 8 35 70 2023-10-03 11:59:04.398397 46  Here all examples I've given are synthetic examples, typically in my case df1 has 10500 rows of data in min frequency spanning one week and df2 has 472963 rows of data in millisecond frequency spanning 20hrs. Any help will be really appreciated.

Answer: If I understand correctly, you could define a cumsum delta from your reference (or first value of df2) and use this as a key for merge_asof: start = pd.Timestamp('2023-09-30 08:02:00') out = pd.merge_asof(df2.assign(delta=df2['Timestamp'].sub(df2['Timestamp'].iloc[0]).cumsum()), df1.assign(delta=df1['time'].sub(start).where(lambda x: x>='0').cumsum()) .dropna(subset=['delta']).rename(columns={'A': 'CC'}), on='delta', direction='forward' ).drop(columns=['delta', 'time'])  Output:  AA BB Timestamp CC 0 27 54 2023-10-03 11:57:57.898397 61 1 28 56 2023-10-03 11:57:59.398397 87 2 29 58 2023-10-03 11:58:00.898397 87 3 30 60 2023-10-03 11:58:02.398397 87 4 31 62 2023-10-03 11:58:03.898397 87 5 32 64 2023-10-03 11:58:05.398397 87 6 33 66 2023-10-03 11:58:06.898397 87 7 34 68 2023-10-03 11:58:08.398397 87 8 35 70 2023-10-03 11:59:04.398397 46  Intermediates:  AA BB Timestamp delta2 A time delta1 0 27 54 2023-10-03 11:57:57.898397 0 days 00:00:00 61 2023-09-30 08:02:00 0 days 00:00:00 1 28 56 2023-10-03 11:57:59.398397 0 days 00:00:01.500000 87 2023-09-30 08:03:00 0 days 00:01:00 2 29 58 2023-10-03 11:58:00.898397 0 days 00:00:04.500000 87 2023-09-30 08:03:00 0 days 00:01:00 3 30 60 2023-10-03 11:58:02.398397 0 days 00:00:09 87 2023-09-30 08:03:00 0 days 00:01:00 4 31 62 2023-10-03 11:58:03.898397 0 days 00:00:15 87 2023-09-30 08:03:00 0 days 00:01:00 5 32 64 2023-10-03 11:58:05.398397 0 days 00:00:22.500000 87 2023-09-30 08:03:00 0 days 00:01:00 6 33 66 2023-10-03 11:58:06.898397 0 days 00:00:31.500000 87 2023-09-30 08:03:00 0 days 00:01:00 7 34 68 2023-10-03 11:58:08.398397 0 days 00:00:42 87 2023-09-30 08:03:00 0 days 00:01:00 8 35 70 2023-10-03 11:59:04.398397 0 days 00:01:48.500000 46 2023-09-30 08:04:00 0 days 00:03:00