December 2018
Beginner to intermediate
682 pages
18h 1m
English
Finding streaks in the data is not a straightforward operation in pandas and requires methods that look ahead or behind, such as diff or shift, or those that remember their current state, such as cumsum. The final result from the first seven steps is a Series the same length as the original that keeps track of all consecutive ones. Throughout these steps, we use the mul and add methods instead of their operator equivalents (*) and (+). In my opinion, this allows for a slightly cleaner progression of calculations from left to right. You, of course, can replace these with the actual operators.
Ideally, we would like to tell pandas to apply the cumsum method to the start of each streak and reset itself after the end of each one. ...