I have a very large data frame from which I would like to pull a subsample, perform some calculation and then write these results into a new data frame. For the sample, please consider:
df_test = pd.DataFrame(np.random.randint(low=0, high=10, size=(5, 5)),
                    columns=['a', 'b', 'c', 'd', 'e'])
df_test
returning this:
    a   b   c   d   e
0   1   9   0   3   0
1   5   4   1   0   3
2   9   3   6   3   5
3   6   2   5   9   7
4   9   0   7   9   5
Now I would like "extract" always 3 rows, rolling from the beginning and calculate the averages (as an example, other calculations would work too) of each column:
df_1
    a   b   c   d   e
0   1   9   0   3   0
1   5   4   1   0   3
2   9   3   6   3   5
df_2 
    a   b   c   d   e
1   5   4   1   0   3
2   9   3   6   3   5
3   6   2   5   9   7
df_3 
    a   b   c   d   e
2   9   3   6   3   5
3   6   2   5   9   7
4   9   0   7   9   5
the result data frame is then
result
    a   b   c   d   e
0   5   5.3 2.3 3   2.7
1   6.7 3   4   4   5
2   8   1.7 6   7   5.3
How can I do that?
 
    