Recommand · October 14, 2021 0

Filtering out data after applying the group by function

My current dataframe looks like this:

        UserID   EventType   Event Time    
0       AG1C      A          05/27/2020 10:20 PM 
1       AG1C      B          05/27/2020 1:22  PM 
2       AG1C      B          05/16/2020 12:58 AM 
3       AG1C      C          05/17/2020 10:34 AM 
4       AG1C      C          05/28/2020 2:10  AM 
.....   

I’m trying to find out the number of unique User IDs that engaged in event A after engaging in event B or event C.

I’ve tried using the python group by function and tried filtering the dataframe using boolean conditions:

new_df.groupby(['User ID'])[(new_df["Event Type"] == "B") | (new_df["Event Type"] == "A")]["Event Time"] <= new_df[(new_df.Type == "C")]["Event Time"]

But it wouldn’t work and I don’t really know how I can approach the problem.
Any help or direction is appreciated, thanks!