Answered step by step
Verified Expert Solution
Question
1 Approved Answer
don't need to find running window quite yet, just the average of this specific window. I need help editing code I keep getting wrong answer.
don't need to find running window quite yet, just the average of this specific window. I need help editing code I keep getting wrong answer. if someone could explain so I understand
You can see in the figure that the moving average calculation is not valid for years near the ends of the list. We must have at least k years before and k years after the year we are computing the average for. In the first part we will focus on just calculating the average and the year for the first window. Prototype the Calculation We will start with implementing the first window to make sure the calculation works before moving to the more difficult problem of sliding the window. For the first valid year in your temperature list, you will calculate the average of the k years before, the year itself, and the k years after. The easiest way to do this is using a list slice. The following three statements compute and print the year and the moving average for the first valid index in a list of temperatures called temps. index=kyear=1880+indexave=sum(temps[index-k:index+k+1])/(2k+1) You should be able to insert these statements at the end of your program to calculate the year and the average. The output of your program for a window size of 20 will eventually look exactly like this: Temperature anomaly filename:SacramentoTemps.csv Enter window size: 20 1900,0.4171 Once you get the calculations for year and average working, format the output so that the values are separated by a comimaand the average temperature is printed with exactly four decimal places using the format string method. \begin{tabular}{|l|r|r|} \hline \multicolumn{1}{|c|}{ A } & \multicolumn{1}{c|}{ B } \\ \hline \multicolumn{1}{|c|}{ Year } & \multicolumn{1}{c|}{ Value } \\ \hline & 1880 & 1.56 \\ \hline & 1881 & 0.08 \\ \hline 1882 & 0.3 \\ \hline & 1883 & 1.44 \\ \hline & 1884 & 2.29 \\ \hline & 1885 & 1.95 \\ \hline & 1886 & 0.63 \\ \hline 1 & 1887 & 0.63 \\ \hline 2 & 1888 & 0.72 \\ \hline 3 & 1889 & 2.99 \\ \hline 4 & 1890 & 0.5 \\ \hline 5 & 1891 & 1.36 \\ \hline 6 & 1893 & 1.03 \\ \hline 7 & 1894 & 0.16 \\ \hline 8 & 1896 & 1.46 \\ \hline 9 & 1897 & 1.23 \\ \hline 0 & 1898 & 0.83 \\ \hline 1 & 1899 & 1.53 \\ \hline \end{tabular}Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started