How to calculate with conditions in pandas?

I have a dataframe like this, I want to calculate and add a new column which follows the formula: Value = A(where Time=1) + A(where Time=3), I don’t want to use A (where Time=5). I know how to do by selecting the cell needed for the formula, but is there any other better ways to perform the calculation? I suspect I need to add a condition but not sure how, any suggestion? Answer Use Series.eq with DataFrame.groupby and Series.cumsum to create groups and add. or if you want to identify it based on the non-equivalence with 5: Output MISSING VALUES