Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with my Python homework. I am stuck on how to get the two averages to compare them. There are two excel files
I need help with my Python homework. I am stuck on how to get the two averages to compare them. There are two excel files that have been turned into arrays. Just not sure how to calculate the averages.
Load libraries H \#\# read excel files import pandas as pd \#\# numerical operators import numpy as np \#\# plot functions import matplotlib.pyplot as plt \#\# inline plotting (i.e., show plots in notebook) \%matplotlib notebook \#\# Read the Excel file containing the annual and global mean temperature from year 850 to 1849 df850_1849 = pd.read_excel ('aaveTS.cesmLME.0850-1849.001.xlsx') \#\# Read column "aaveTS" and convert the Pandas dataframe to a numpy array aaveTS850_1849 =np.array( df850_1849['aaveTS' ]) \#\#\# \#\#\# \#\#\# \#\#\# \#\#\# \#\#\# \#\# Read the Excel file containing the annual and global mean temperature from year 2006 to 2100 df2006_2100= pd.read_excel('aaveTS.cesmLME.2006-2100.002.xlsx') \#\# Read column "aaveTS" and convert the Pandas dataframe to a numpy array Workspace 1: Function that calculates the mean of an array The mean () of an array x with length N (i.e., the number of elements in x is N ) is defined as: =N1i=0N1xi Exercise: Complete the function (1) Create a variable mu that is equal to the sum of the elements in variable x divided by the number of elements in x Hint 1: use to calculate the sum of all elements in x https:/umpy.org/doc/stable/reference/generatedumpy.sum.html Hint 2: Use function len() to calculate the number of elements in x https://docs.python.org/3/library/functions.html\#len Nothing will be printed to the screen when you run this function! M def my_mean(x): \#\# Ex 1: Calculate the mean (mu) of the input array x \#\# hint, mu=( sum of x)/ number of elements in x mu=npsum(x)/N \#\# Return variable mu from the function return mu \#\# Ex 3: Print variables my_mu and npmu to the screen print( '\my_mu:') print(' np_mu:') \#\# Ex 4: Print the ratio of variables my_mu and npmu to the screen print(' The ratio of my_mu / np_mu:') \my_muStep 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