I need to find the data in-between certain triggers in a data frame that contains several Real-time signals and one timestamp column. These triggers are saved on a separate data frame. I have a working solution with a for-loop, which takes ages on the relatively large dataset I am using. I am trying to speed things up with list-comprehensions, but I cannot find a working solution. Does anyone have an idea of how to do this faster?
The for-loop solutions:
This is how the trigger data frame looks like:
timestamp_x start_trig id timestamp_y end_trig
0 1592724037612 1.0 12 1592724068408 -1.0
1 1592724459283 1.0 23 1592724490290 -1.0
2 1592724514246 1.0 17 1592724545450 -1.0
And this is the code to append the rows in the old data frame with the name "data" to the new data frame with the name new_df
for i in range(len(df_trig)):
mask = data[(data['timestamp'] > df_trig.iloc[i].timestamp_x) & (data['timestamp'] < df_trig.iloc[i].timestamp_y)]
new_df = new_df.append(mask)
This is what I tried to solve this with a generator, which is not working for me:
new_df = pd.DataFrame(data[(data['timestamp'] > low_lim) & (data['timestamp'] < upp_lim)] for low_lim,upp_lim in zip(df_trig['timestamp_x'], df_trig['timestamp_y']))
Thank you for your answers already in advance!
EDIT:
The original data frame contains looks as following:
timestamp id param1
0 1592724037612 23 56.1
1 1592724037712 23 56.1
2 1592724037812 23 56.0
...
100 1592724047612 17 54.7
The objective is to move all the rows, which are in-between any of the trigger pairs from the other data frame. Therefore, the new data frame looks almost identically except that the rows are missing which are outside of the ranges defined in the trigger data frame.