How to subset row of condition with some of N rows before the condition meet , more faster than my code?
I think you can using the ffill
with limit
, and find the notnull
index
, slice the dataframe
yourdf=df[df.temperature.where(df.temperature<40).bfill(limit=24).notnull()].copy()