Having this kind of pandas dataframe
df = pd.DataFrame({
'ts_diff':[0, 0, 738, 20, 29, 61, 42, 18, 62, 41, 42, 0, 0, 729, 43, 59, 42, 61, 44, 36, 61, 61, 42, 18, 62, 41, 42, 0, 0]
})
ts_diff - is duration in milliseconds between events
Would like to generate another column ts_diff_incr that would be based on ts_diff.
ts_diff_incr - would be duration in msec between current step and event start (where ts_diff was zero)
Please see the calculation logic in the image below.
What is the best way to achieve this without for loops and instead using Vectorization?

df['ts_diff_incr'] = df.groupby(df['ts_diff'].eq(0).cumsum()).cumsum()