title: Filtering out outliers in Pandas dataframe with rolling median
body: <p>I am trying to filter out some outliers from a scatter plot of GPS elevation displacements with dates</p>
  
  <p>I'm trying to use df.rolling to compute a median and standard deviation for each window and then remove the point if it is greater than 3 standard deviations.</p>
  
  <p>However, I can't figure out a way to loop through the column and compare the the median value rolling calculated.</p>
  
  <p>Here is the code I have so far</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  def median_filter(df, window):
      cnt = 0
      median = df['b'].rolling(window).median()
      std = df['b'].rolling(window).std()
      for row in df.b:
        #compare each value to its median
  
  
  
  
  df = pd.DataFrame(np.random.randint(0,100,size=(100,2)), columns = ['a', 'b'])
  
  median_filter(df, 10)
  </code></pre>
  
  <p>How can I loop through and compare each point and remove it?</p>