Dataframe_1:
time
, travel_time
and next_arrival_time
is a time interval
0 1142922 32 2022-06-01 07:22:57.070 2022-06-01 07:32:33.149000
1 1142954 32 2022-06-01 07:49:07.285 2022-06-01 07:56:41.369000
2 1142978 32 2022-06-01 08:14:49.478 2022-06-01 08:22:47.571000
3 1143005 32 2022-06-01 08:36:41.684 2022-06-01 08:43:17.741579
4 1143025 32 2022-06-01 09:01:29.883 2022-06-01 09:07:34.852750
5 1143046 32 2022-06-01 09:28:12.099 2022-06-01 09:35:41.990302
6 1143070 32 2022-06-01 09:48:50.258 2022-06-01 10:25:31.174000
7 1143107 32 2022-06-01 10:35:41.243 2022-06-01 10:41:29.296000
8 1143125 32 2022-06-01 10:55:17.428 2022-06-01 11:06:51.553000
9 1143145 32 2022-06-01 11:25:57.681 2022-06-01 11:34:33.754000
Dataframe_2: the time in truckdate is every two seconds truckdate
0 2022-06-01 00:07:00.000000
1 2022-06-01 00:07:02.000000
2 2022-06-01 00:07:04.000000
3 2022-06-01 00:07:06.000000
4 2022-06-01 00:07:08.000000
5 2022-06-01 00:07:10.000000
6 2022-06-01 00:07:12.000000
7 2022-06-01 00:07:14.000000
8 2022-06-01 00:07:16.000000
9 2022-06-01 00:07:18.000000
I want to know if each element of the column "truncdate" (data_2) belongs to the interval "time_traveling" between "next_time_arrival" (data_1) and if it belongs and adds a column in data_2 with the "Id" of data_1.
I tried with this code but it doesn't work.
for i in data_2["truckdate"]:
for n in data_1.index:
while (i>=data_1['tiem_viajando'][n]) and (i<=data_1['next_tiem_llegada'][n]):
data_2["Nuevo"][i]=data_1["id"][n]
print(data_2)