temperature.py 1000 Bytes
from plot import plot_data 

def process_data(file):
    temp_data_file = open(file)

    data = []
    for line in temp_data_file.readlines():
        split_line = line.split(",")
        date = split_line[0].split("/")
        day = ____(a)____
        month = ____(b)____
        year = ____(c)____
        temperature = float(____(d)____)
        data.append(((year, month, day), temperature))

    return sorted(data)

def collect_averages_and_plot(infile, outfile):
    data = process_data(____(a)____)
    xs = []
    ys = []

    prev = None
    total = 0.0
    num = 0

    for x in data:
        d = ____(b)____
        t = ____(c)____
        if prev != d and prev is not None:
            xs.append(____(d)____)
            ys.append(____(e)____)
            total = 0.0
            num = 0
        total += t
        num += 1
        prev = d
    xs.append(____(f)____)
    ys.append(____(g)____)

    plot_data(____(h)____, xs, ys)

collect_averages_and_plot("pasadena.csv", "out.png")