1

I've dataframe like that:

price period
124.22 5
126.51 6
121.3 6
125.25 4

df['lowest'] = df['price'].rolling(window=30).min().shift(1)

Now the rolling is applied base on 30 window. I need to apply for each row the corresponding period. Es: For first line price = 124.22 , window = 5

Something like that (this code not working...):

df['lowest'] = df['price'].rolling(window=df['period']).min().shift(1)

Damiano Dotto
  • 105
  • 1
  • 10
  • Does this answer your question? [pandas rolling computation with window based on values instead of counts](https://stackoverflow.com/questions/14300768/pandas-rolling-computation-with-window-based-on-values-instead-of-counts) – Gonçalo Peres Oct 19 '22 at 09:29

0 Answers0