title: how to do Backward moving average and Simple Moving average?
body: <p>I have done forward moving average for my data but I'm confused about how to do backward moving average and moving average.
  I have a dataset like Date and Raw Data as my dataset. And I have used the below code for forward-moving average</p>
  <pre><code>indexer = pd.api.indexers.FixedForwardWindowIndexer(window_size=4)
  df[&quot;Transformed Data&quot;] = df['Raw Data'].rolling(window=indexer, min_periods=1).mean()
  df.head()
  </code></pre>
  <p>Output:</p>
  <pre><code>          Date          Raw Data    Forward Mvg Avg Data   
  0    01-01-2018              100    100.0
  1    08-01-2018                0    200.0
  2   15-01-2018               300    200.0
  3   22-01-2018                 0    300.0
  4   29-01-2018               500    400.0
  5   05-02-2018                 0    350.0
  6   12-02-2018               700    700.0
  </code></pre>
  <p>I have given size as 4 so the first value of Forward Moving Avg Data is (100+0+300+0)/4 and so on for other values</p>
  <pre><code>df[&quot;BACKWARD Transformed Data&quot;] = df['Raw Data'].rolling(window=4, min_periods=1).mean()
  </code></pre>
  <p>Output</p>
  <pre><code>          Date          Raw Data    BACKWARD Transformed Data   
  0    01-01-2018              100    100.0
  1    08-01-2018                0     50.0
  2   15-01-2018               300    133.333
  3   22-01-2018                 0     50.0
  4   29-01-2018               500    200.0
  5   05-02-2018                 0    200.0
  6   12-02-2018               700    300.0
  </code></pre>
  <p>If you see the first value of backward transformed data is 100/1, 0+100/2, (300+0+100)/3, (0+300+0+100)/4, (500+0+300+0)/4, (0+500+0+300)/4, (700+0+500+0)/4.</p>
  <p>In the same way, simple moving average</p>
  <p>Expected Output:</p>
  <pre><code>          Date          Raw Data    Mvg Avg Data   
  0    01-01-2018              100    50.0
  1    08-01-2018                0    133.333
  2   15-01-2018               300    100.0
  3   22-01-2018                 0    200.0
  4   29-01-2018               500    200.0
  5   05-02-2018                 0    300.0
  6   12-02-2018               700    400.0
  </code></pre>
  <p>If you see the value of simple moving avg as I gave window size as 4 so it should do an average of two values above and one value below, for 3rd value of above result it is (0+300+0+500)/4 and for the last values as there is no value after 700 then it will be (700+0+500)/3 and for first values, there are no values above 100 so it will be (100+0)/2 and so on for others. For example if I say window_size as 5 then it should do an average of two values above and two value below.</p>