Давайте попробуем:
import pandas as pd
import numpy as np
df = pd.DataFrame({'ID':np.arange(1,21)
,'Place':['A']*10+['B']*10
,'Date':d.to_list() * 2
,'event':[0]*5+[1]+[0]*7+[1]+[0]*6
,'Flag':[0,0,-3,-2,-1,1,2,3,4,0,-3,-2,-1,
1,2,3,4,0,0,0]},
index = np.arange(1,21))
n=3
s = df['event'].rolling(n*2+1, center=True, min_periods=1).max()
s = s.cumsum()
l = ((s - s.where(s.duplicated()).ffill())).fillna(0)
l.update(l[l>n]+1)
df['Flag'] = (l - n-1).where(l.gt(0), 0)
print(df)
Вывод:
ID Place Date event Flag
1 1 A 2019-01-01 0 0.0
2 2 A 2019-01-02 0 0.0
3 3 A 2019-01-03 0 -3.0
4 4 A 2019-01-04 0 -2.0
5 5 A 2019-01-05 0 -1.0
6 6 A 2019-01-06 1 1.0
7 7 A 2019-01-07 0 2.0
8 8 A 2019-01-08 0 3.0
9 9 A 2019-01-09 0 4.0
10 10 A 2019-01-10 0 0.0
11 11 B 2019-01-01 0 -3.0
12 12 B 2019-01-02 0 -2.0
13 13 B 2019-01-03 0 -1.0
14 14 B 2019-01-04 1 1.0
15 15 B 2019-01-05 0 2.0
16 16 B 2019-01-06 0 3.0
17 17 B 2019-01-07 0 4.0
18 18 B 2019-01-08 0 0.0
19 19 B 2019-01-09 0 0.0
20 20 B 2019-01-10 0 0.0