If I have a csv data that gives two row values of:
years grades
2001 98
2001 75
2008 100
2003 57
2008 50
I have more values but I will try to explain what I am trying to get here.
I want to get the average for each year. For instance, for 2001, the answer would be (98+75)/(# of counts 2001, which is 2 in this case).
def construct_values(filing):"""Parameters----------Returns-------years: array of integersaverage_grades: array of floats
"""years, average_grades = [], []grades = []with open('grades.csv', 'r') as filing:next(filing)for row in file_path:year, grade = (s.strip() for s in row.split(','))years.append(year)grades.append(grade)return years, average_grades
What I did was just to get two arrays of years and grades. I don't know how to get average arrays and then print out like:
2001, 88.5555
for instance if 88.555 is average.
Instead of being them as dictionaries, what I want to have are two arrays that will just return together.