0

I'm given a DataFrame, as shown in the image below: DataFrame example

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?

Timus
  • 10,974
  • 5
  • 14
  • 28
  • can you share the code showing what you have done so far? – user_na Jul 21 '22 at 14:01
  • Please add a [mre](https://stackoverflow.com/help/minimal-reproducible-example) (also look [here](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples)) that illustrates your problem, including the expected output. – Timus Jul 21 '22 at 14:55

1 Answers1

0

Just remove the rows based on duration:

df.drop(df[df.['duration']> 60].index, inplace=True)

Baraa Zaid
  • 362
  • 1
  • 9