I have a dataframe with two columns. I want to find the rolling 5 period max of the first column and calculate the sum of values and a second column for the row of the rolling max and the the preceding 4 rows.
Below is an example of the desired output with Col1 and Col2 as mentioned above, a third column of the rolling max and a final column of the desired result of the calculation
Here is code to set the first three columns:
data ={'Col1': [4,2,3,4,5,6,5,4,3,2,1,4,3,2,1],
'Col2' :[10,20,10,15,10,20,10,15,10,20,10,15,10,20,10]}
df = pd.DataFrame(data)
df['Col1_Rolling5_Max'] = df['Col1'].rolling(5).max()
df
Here is an example of the desired output:
