I have two questions about moving average calculation in Python vs moving average example in a textbook.
The task is to calculate a three-year moving average. In Python, I am using
df['moving_average'] = df['production'].rolling(window = 3).mean()
and get the following results:
I don't understand why in the textbook, they start with the middle year i.e. not from 2000 but 1999?

- In the textbook, they say, 'Four-year, six-year, and other even-numbered-year moving averages present one minor problem regarding the centering of the moving totals and moving averages. Note in Table 18–3 below there is no center time period, so the moving totals are positioned between two time periods. The total for the first 4 years (42) is positioned between 2009 and 2010. The total for the next 4 years is 43. The averages of the first four years and the second 4 years (10.50 and 10.75, respectively) are averaged, and the resulting figure is centered on 2010. This procedure is repeated until all possible four year averages are computed.' And get the following results:

However, if you do it in Python, using the above function, you will get:

Their logic seems to make sense. Does it mean that the function in Python is just simplification and to get more accurate results, I need to develop a formula myself? And the question still remains why they start with the 3rd year.

