I have a multi-index dataframe in pandas, where index is on ID and timestamp. I want to be able to compute a time-series rolling sum of each ID but I cant seem to figure out how to do it without loops.

Notice the overlap between IDs 0 and 1 and 1 and 2 at the edges (I dont want that, messes up my calculations) . One possible way to get around this is to using groupby on IDs and then loop through that groupby and then apply a rolling_sum