Language: Python 3.8
I have a dataframe that consists of a series of people (each appearing multiple times in the dataframe), dates, and binary variables. I am trying to figure out how many people after a specific event (marked by one of the binary variables) went on to have other positive events. So for example, say the table looks something like this:
| ID | Date | Earthquake | Fire | Storm Damage |
|----|----------|------------|------|--------------|
| 1 | 1/21/21 | 0 | 0 | 0 |
| 2 | 2/3/21 | 1 | 0 | 0 |
| 3 | 2/4/21 | 0 | 1 | 0 |
| 1 | 2/10/21 | 1 | 0 | 0 |
| 1 | 2/28/21 | 0 | 1 | 1 |
| 2 | 3/5/21 | 0 | 0 | 1 |
So in this example, after the first incidence of earthquake, one person went on to have a fire and two went on to have storm damage.
My problem is, I can't quite figure out how to do this. I think I need to use groupby to group all the IDs together, but I'm a bit stuck after that point.