I have a long list with some values. I want to define a function that take the list and calculates the average for every 24 values in the list, and returns the average values as a list. How do I do this? I have 8760 elements in the list, and the list returned should give 8760/24=365 elements.
hourly_temp = ['-0.8', '-0.7', '-0.3', '-0.3', '-0.8',
'-0.5', '-0.7', '-0.6', '-0.7', '-1.2', '-1.7...] #This goes on, it's 8760 elements
def daily_mean_temp(hourly_temp):
first_24_elements = hourly_temp[:24] #First 24 elements in the list
Is this correct? I get an error saying: TypeError: cannot perform reduce with flexible type
def daily_mean_temp(hourly_temp):
averages = [float(sum(myrange))/len(myrange)
for myrange in zip(*[iter(hourly_temp)]*24)]
return averages