M. Lap
M. Lap

Reputation: 1

Python pandas find max sum of 5 consecutive values in a dataframe

I have the following dataframe

    year  julian  hour    1    2  3    4 ...    54  55   56   57   58   59   60
0   2018     152     0  0.0  0.0  0  0.0 ...   0.0   0  0.2  0.0  0.0  0.0  0.0
1   2018     152     1  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
2   2018     152     2  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
3   2018     152     3  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
4   2018     152     4  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
5   2018     152     5  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
6   2018     152     6  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
7   2018     152     7  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
8   2018     152     8  0.0  0.2  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.4
9   2018     152     9  0.0  0.2  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
10  2018     152    10  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
11  2018     152    11  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
12  2018     152    12  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
13  2018     152    13  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.2  0.0  0.0  0.0
14  2018     152    14  0.2  1.0  1  0.8 ...   0.0   0  0.0  0.0  0.0  0.2  0.0
15  2018     152    15  0.0  0.0  0  0.0 ...   0.2   0  0.0  0.0  0.0  0.0  0.2
16  2018     152    16  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
17  2018     152    17  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
18  2018     152    18  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
19  2018     152    19  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
20  2018     152    20  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.0
21  2018     152    21  0.0  0.0  0  0.0 ...   0.8   1  0.8  0.6  0.0  0.0  0.0
22  2018     152    22  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.0  0.0  0.0  0.2
23  2018     152    23  0.0  0.0  0  0.0 ...   0.0   0  0.0  0.2  0.4  0.2  0.2

It contains minute rainfall totals. I have 60 values for each hour of the day. How would I find the maximum 5 minute consecutive total for each julian day?

Upvotes: 0

Views: 192

Answers (1)

Scott Boston
Scott Boston

Reputation: 153460

Let's try:

df.set_index(['year','julian','hour']).rolling(5, axis=1).sum().max(1)

Upvotes: 4

Related Questions