I have the following table:
| user | id | time | event |
|---|---|---|---|
| a | 1 | 2021.12.12 10:08:39:399 | viewed |
| a | 2 | 2021.12.12 10:08:39:402 | clicked |
| a | 3 | 2021.12.23 3:43:19:397 | viewed |
| a | 4 | 2021.12.23 3:47:11:131 | viewed |
| a | 5 | 2021.12.30 19:20:31:493 | viewed |
How would I go about trying to find the conversion rate grouped by each user? By this I mean the percentage of views that are followed up by a click within a certain timeframe (lets say 30s). In this case user a has viewed four times and clicked once, with the click being in the allotted timeframe - giving us a conversion rate of 1/4 = 25%.
I tried doing this by splitting the frame by event then using pd.merge_asof() which works for most cases but sometimes user id's are replaced by nulls and sometimes not all viewed events are carried over into the new table. Would appreciate the help!