Let's say I have a data frame with 2 columns, 1st column contains the activities such as work, home, sleep etc. and the 2nd column are the duration of each activity.
while iterating through the rows, I want to find out the duration of the last activity of 'sleep' during the current activity I am in.
Is there an easy way to do that?
my data:
duration = np.random.randint(20, size = 30)
activities = ['work', 'home', 'sleep', 'home','work', 'sleep','work', 'home','sleep', 'home','work', 'sleep','work', 'home','work', 'sleep','work', 'home','work', 'sleep','work', 'home','work', 'sleep','work', 'home','work', 'home', 'work', 'sleep']
activity_df = pd.DataFrame({'activities':activities, 'duration':duration})