college student needs your help passing

This is the place for queries that don't fit in any of the other categories.

college student needs your help passing

Postby Larred » Thu May 08, 2014 6:22 pm

Hello, this is my first post here, i am designing this code as my final for my intro to computer science course, prior experience is very limited.
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 :D 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)

     
       
Last edited by stranac on Thu May 08, 2014 6:25 pm, edited 1 time in total.
Reason: First post lock.
Larred
 
Posts: 3
Joined: Thu May 08, 2014 6:18 pm

Re: college student needs your help passing

Postby stranac » Thu May 08, 2014 6:35 pm

You should show us a sample of the file, let us know what results you get for that data and how those results are different from what you expected.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1092
Joined: Thu Feb 07, 2013 3:42 pm

Re: college student needs your help passing

Postby Larred » Thu May 08, 2014 6:38 pm

ok
here is the output if you run it how it is currently
worst monthly averages for Google were:
Code: Select all
9 2004 374.36
9 2004 375.11
9 2004 375.49
9 2004 375.79
9 2004 376.04
9 2004 376.2
6 best months for google were:
9 2004 374.36
9 2004 375.11
9 2004 375.49
9 2004 375.79
9 2004 376.04
9 2004 376.2

>>>
using the numbers from this site https://finance.yahoo.com/q/hp?s=GOOGL&a=07&b=19&c=2004&d=07&e=19&f=2008&g=m
Edit: sorry forgot the code tags
Last edited by Larred on Thu May 08, 2014 6:48 pm, edited 1 time in total.
Larred
 
Posts: 3
Joined: Thu May 08, 2014 6:18 pm

Re: college student needs your help passing

Postby Kebap » Thu May 08, 2014 6:40 pm

stranac wrote:and how those results are different from what you expected.


Maybe take a look at New Users, Read This ;)
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 365
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 4 guests

cron