How do I perform a summation of `n` rows at a time in pandas?

Viewed 1833

Given a data frame

     A
0   14
1   59
2   38
3   40
4   99
5   89
6   70
7   64
8   84
9   40
10  30
11  94
12  65
13  29
14  48
15  26
16  80
17  79
18  74
19  69

This data frame has 20 columns. I would like to group n=5 rows at a time and sum them up. So, my output would look like this:

     A
0  250
1  347
2  266
3  328 

df.rolling_sum will not help because it does not allow you to vary the stride when summing.

What other ways are there to do this?

3 Answers
Related