I'm given a DataFrame, as shown in the image below:
For each user-item pair, I should collect all the events, but the events that happened 1 hour after the maximal timestamp for this particular user-item pair should be removed.
One way I thought of was to extract the user-item pair events, sort them by timestamp, then remove the unnecessary events, and append to some final DataFrame (used for collection). Is there a faster way this could be done?