the goal is to make a program that will look at Google stock data from 2004-2008 and give the best and worst 6 months. so far i have it to where it will print numbers and dates just not the correct ones

help would be appreciated thanks in advance

- Code: Select all
`import operator`

def get_data_list(file_name):

data_file = open(file_name, "r")

data_list = [] # always start with an open list

for line_str in data_file:

data_list.append(line_str.strip().split(',')) # removes all commas from the csv file

return data_list

def get_monthly_averages_list(data_list): # This function does the math to determine the average

monthly_average_list = []

monthly_average = 0.0

monthly_volume = 0.0

extremly_important_variable ='9'

yearly = '2008'

for line in data_list:

month = line[0].split('/')[0]

year = line[0].split('/')[2]

close = float( line [6])

volume = float( line [5])

monthly_average += close*volume

monthly_volume += volume

if month != extremly_important_variable:

new_monthly_average = round(monthly_average/monthly_volume,2)

average_tuple = (extremly_important_variable, yearly, new_monthly_average)

monthly_average_list.append(average_tuple)

yearly = year

return monthly_average_list

def monthly_average_info(monthly_average_list):

K = 0

print('worst monthly averages for Google were:')

for K in range (0,6):

monthly_average_list[::-1]

monthly_average_list.sort(key=operator.itemgetter(1))

test = (monthly_average_list[K][0] + ' ' + monthly_average_list[K][1] + ' ' + str(monthly_average_list[K][2]))

print(test)

print ( "6 best months for google were:")

for x in range (0,6):

monthly_average_list[::-1].sort(key=operator.itemgetter(2))

Test2 = (monthly_average_list[x][0] + ' ' + monthly_average_list[x][1] + ' ' + str(monthly_average_list[x][2]))

print(Test2)

Datalist = get_data_list('table.csv')

Datalist.pop(0)

monthly_average_list = get_monthly_averages_list(Datalist)

monthly_average_info(monthly_average_list)