I am working on a stock data, I am trying to get the Maximum(the largest value) of the "Last" value in the last 15 minutes. Which is shown in the expected output in column named Max.
The code i tried takes so long to compute, i am sure that there is a something missing. Not sure about how to do it since i am new to pandas calculations for time-series. Could anyone please give your solution. Thanks
Code Tried:
for c in df["Last"].dropna():
df[c]=df["Last"].fillna(0).rolling('15T').max()
new="Prev15max_min"+df["Last"].dropna()
df.loc[:df.index[0]+pd.DateOffset(minutes=15),new]=np.nan
The data i have is shown below
Timestamp Last
1/20/19 12:15 3071.56
1/20/19 12:17 3097.82
1/20/19 12:17 3097.82
1/20/19 12:18 3095.25
1/20/19 12:19 3087.42
1/20/19 12:20 3095.29
1/20/19 12:21 3095.25
1/20/19 12:22 3093.11
1/20/19 12:23 3103
1/20/19 12:24 3095
1/20/19 12:25 3100.6
1/20/19 12:26 3099.84
1/20/19 12:27 3098.77
1/20/19 12:29 3097.24
1/20/19 12:29 3090
1/20/19 12:30 3090
1/20/19 12:31 3094.2
The expected output
Timestamp Last Max
1/20/19 12:15 3071.56
1/20/19 12:17 3097.82
1/20/19 12:17 3097.82
1/20/19 12:18 3095.25
1/20/19 12:19 3087.42
1/20/19 12:20 3095.29
1/20/19 12:21 3095.25
1/20/19 12:22 3093.11
1/20/19 12:23 3103
1/20/19 12:24 3095
1/20/19 12:25 3100.6
1/20/19 12:26 3099.84
1/20/19 12:27 3098.77
1/20/19 12:29 3097.24
1/20/19 12:29 3090 3103
1/20/19 12:30 3090 3103
1/20/19 12:31 3094.29 3103