I have a df
   uid       timestamp               event
   34900     2015-01-01 00:00:10     5
   90100     2015-01-07 00:00:00     4
   90100     2015-03-02 00:00:00     9
   34900     2015-01-03 00:00:00     5
   34900     2015-01-01 00:40:00     6
   34900     2015-01-01 00:00:01     2
   90100     2015-03-01 00:07:00     5
   34900     2015-01-04 00:00:09     8
   34900     2015-01-07 00:00:10     2
   90100     2015-01-01 20:00:00     1
It has events (1-9) occurring on some unique ids (34900,90100,..) timestamped as datetime.
I am trying to find what happens before and after an event (event=5) occurs on each unique id. My thinking is to subset the df into each unique and retain the adjacent event for each 5 event that happens.
So I will like to know how to retrieve the following dataframes below from the df above
uid=34900
   timestamp               before      after
   2015-01-01 00:00:10     2           6
   2015-01-03 00:00:00     6           8
uid=90100
   timestamp               before      after
   2015-03-01 00:07:00     4           9