Python CSV help!

Reply

Join Date: May 2008
Posts: 19
Reputation: ssDimensionss is an unknown quantity at this point 
Solved Threads: 0
ssDimensionss ssDimensionss is offline Offline
Newbie Poster

Python CSV help!

 
0
  #1
May 10th, 2008
Hi i have a CSV file that looks something like this:
Name ASX_Code Date SharePrice
ACACIA RESOURCES AAA 19990630 1.75
ACACIA RESOURCES AAA 19980630 1.72
ABSOLUTE RETURN FUND UNIT AAB 20040625 0.9
ABSOLUTE RETURN FUND UNIT AAB 20030630 0.85
AUSTRALIAN AGRICULT. AAC 20070629 2.95
AUSTRALIAN AGRICULT. AAC 20060630 1.935
AUSTRALIAN AGRICULT. AAC 20050630 1.71
AUSTRALIAN AGRICULT. AAC 20040625 1.23
AUSTRALIAN AGRICULT. AAC 20030630 1.08
AUSTRALIAN AGRICULT. AAC 20020628 0.67
AGRI ENERGY LIMITED AAE 20070629 0.325
AUSTRALIAN ETHANOL AAE 20060630 0.585
AUSTRALIAN ETHANOL AAE 20050630 0.26
ALCOA INC. CDI AAI 20070629 47
ALCOA INC. CDI AAI 20060630 42.75
ALCOA INC. CDI AAI 20050630 39.99
ALCOA INC. CDI AAI 20040625 46.25
ALCOA INC. CDI AAI 20030630 66
ALCOA INC. CDI AAI 20020628 66.6
A1 MINERALS LIMITED AAM 20070629 0.195
A1 MINERALS LIMITED AAM 20060630 0.185
A1 MINERALS LIMITED AAM 20050630 0.26
A1 MINERALS LIMITED AAM 20040625 0.52

well yeah it looks something like that its the data of a list of companies and their shapes prices in different dates. I was asked to write a code on which company has the higghest share value and dont have much of a clue as to how to start can any1 help? thx
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 37
Reputation: kdoiron is an unknown quantity at this point 
Solved Threads: 3
kdoiron's Avatar
kdoiron kdoiron is offline Offline
Light Poster

Re: Python CSV help!

 
0
  #2
May 12th, 2008
How do you think it should be approached? What do you think needs to be done? Let's hear your ideas first - even in English rather than in Python, if that's easier. We can take it from there.
But I don't like SPAM!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,273
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 175
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Python CSV help!

 
0
  #3
May 12th, 2008
Python has a module csv that will make your life easier handling csv files.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 110
Reputation: solsteel is on a distinguished road 
Solved Threads: 31
solsteel solsteel is offline Offline
Junior Poster

Re: Python CSV help!

 
0
  #4
May 12th, 2008
Assuming your data actually has commas in the appropriate places, the following code will determine the company with the highest stock price:
  1. import csv
  2.  
  3. f = open(your_data.csv)
  4. reader = csv.reader(f)
  5. # save header items
  6. headerList = reader.next()
  7. # Create a dictionary with company name and stock prices
  8. dataDict = {}
  9.  
  10. for line in reader:
  11. dataDict.setdefault(line[0], []).append(line[-1])
  12. f.close()
  13.  
  14. dataList = [[max(value), key] for key, value in dataDict.iteritems()]
  15. dataList.sort()
  16. print '%s had the highest stock price of $%0.2f' % (dataList[-1][1], float(dataList[-1][0]))
Output:
>>> ALCOA INC. CDI had the highest stock price of $66.60
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC