0

I have a dataframe that looks like the picture below and I am trying to calculate the rolling average of the ANGLE column like this.

tad3["angl_avg"]=tad3['ANGLE'].rolling(30).mean()

I want to exclude the max and min of each window when calculating the rolling average but cannot find a parameter for it- could someone help me with this?

dataframe image

Cher K
  • 13
  • 3
  • Welcome to Stack Overflow. Please do not include images of data. Always put your data in text format, so it can be copy/pasted, or better still post python code that creates your sample dataframe. This way people will actually be able to use the data to produce the results you expect. For more information, see [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – AlexK Jun 06 '22 at 20:35
  • You can write a function to drop min and max values in each window and calculate the mean of the remaining values. Then use it with `df['angle'].rolling(30).apply(your_function)`. One thing you will need to clarify is what happens when there are multiple rows with same max or same min value in the window. – AlexK Jun 06 '22 at 20:39

0 Answers0