The problem that I am facing is how i can reject a window of 10 rows if one or many of the rows consist of an outlier while computing rolling average using python pandas? The assistance i require in is the conditional logic based on the following scenarios mentioned below
The condition on the outlier in a window is:
The upper bound for outlier is 15, the lower bound is 0
if the frequency of occurrence of outlier in a window is greater than 10%, we reject that particular window and move next.
- if the frequency of occurrence of outlier in a window is less than 10%, we accept the particular window with the following changes: 1) replace the value of the outlier with the value derived from the average of the non-outlier values i.e. the rest of the 9 rows, then averaging the same window again before moving next
Here's the following code till now:
_filter = lambda x: float("inf") if x > 15 or x < 0 else x
#Apply the mean over window with inf to result those values in
result = df_list["speed"].apply(_filter).rolling(10).mean().dropna()
#Print Max rolling average
print("The max rolling average is:")
result.max()