I am trying to find the average values for each month by using a function that references a sorted list of tuples containing (date,value) where date is a string and in the format yyyy-mm-dd and value is a float. The first entry in the data set is not showing up and I believe there may be more errors that I am not aware of. This is what I have so far in Python (note, previous functions not included):
def value_avg(previous_tuple_list):
start_month=tup_list[0][0]
start_month1=start_month.split("/")
start_month2=start_month1[1]
value_total=0
value_count=0
value_avglist=[]
for item in tuple_list:
value_month=tup[0]
value_month1=value_month.split("/")
value_month2=value_month1[1]
value=item[1]
if value_month2==start_month2:
value_sum += value
value_count += 1
else:
value_avg=(value_sum / value_count)
date_no_day= item[0][:7]
value_avg_tup=(value_avg, date_no_day)
value_avglist.append(value_avg_tup)
value_sum -= value_sum
value_count -= value_count
start_month2 = value_month2