I hope you can help me, I want to get all the activity according to a condition.
I have a dataframe like this:
| ID | Number | Activity |
|---|---|---|
| 1 | 1 | Get Up |
| 1 | 2 | Wash |
| 1 | 3 | Dress Up |
| 2 | 1 | Get Up |
| 2 | 2 | Dress Up |
| 2 | 3 | Eat |
| 2 | 4 | Work |
I have as Target Activity Dress Up, so I should look for the Number of the activity and remove all the number after the number of target activity The output:
| ID | Number | Activity |
|---|---|---|
| 1 | 1 | Get Up |
| 1 | 2 | Wash |
| 1 | 3 | Dress Up |
| 2 | 1 | Get Up |
| 2 | 2 | Dress Up |
I have tried to use the function where but it removes all rows expect the one with target activity:
df= pd.read_csv('data.csv')
End_act = 'Dress Up'
cond = df['Activity']==Endact
df = df[ df['Number']<= df['Number'].where(cond)]