- Before we get started with the actual flights dataset, let's practice counting streaks of ones with a small sample Series:
>>> s = pd.Series([0, 1, 1, 0, 1, 1, 1, 0])>>> s0 01 12 1
3 0
4 1
5 1
6 1
7 0
dtype: int64
- Our final representation of the streaks of ones will be a Series of the same length as the original with an independent count beginning from one for each streak. To get started, let's use the cumsum method:
>>> s1 = s.cumsum()>>> s10 0
1 1
2 2
3 2
4 3
5 4
6 5
7 5
dtype: int64
- We have now accumulated all the ones going down the Series. Let's multiply this Series by the original:
>>> s.mul(s1)0 0
1 1
2 2
3 0
4 3
5 4
6 5
7 0
dtype: int64
- We have only non-zero values where we originally had ones. This result is ...