| | |
Python CSV help!
![]() |
•
•
Join Date: May 2008
Posts: 19
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Mar 2007
Posts: 110
Reputation:
Solved Threads: 31
Assuming your data actually has commas in the appropriate places, the following code will determine the company with the highest stock price: Output:
>>> ALCOA INC. CDI had the highest stock price of $66.60
Python Syntax (Toggle Plain Text)
import csv f = open(your_data.csv) reader = csv.reader(f) # save header items headerList = reader.next() # Create a dictionary with company name and stock prices dataDict = {} for line in reader: dataDict.setdefault(line[0], []).append(line[-1]) f.close() dataList = [[max(value), key] for key, value in dataDict.iteritems()] dataList.sort() print '%s had the highest stock price of $%0.2f' % (dataList[-1][1], float(dataList[-1][0]))
>>> ALCOA INC. CDI had the highest stock price of $66.60
![]() |
Similar Threads
- Fixed width to csv conversion (Python)
- how to create csv file (Python)
- Python Regular Expression (Python)
- csv file split (Python)
- read and write csv file using csv module (Python)
- Reading CSV files (Python)
- how to read spread sheet in Python? (Python)
- Python Imaging (Python)
Other Threads in the Python Forum
- Previous Thread: Out of the blue, a project requires Python...
- Next Thread: Press Any Key to Continue
| Thread Tools | Search this Thread |
abrupt accessdenied anti apache application approximation argv array beginner book builtin calculator change converter countpasswordentry curved dan08 dictionaries dictionary dynamic edit enter examples file float format function gui heads homework import inches input java keyboard lapse launcher library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pyopengl python random recursion redirect remote reverse scrolledtext session simple software sprite statictext statistics string strings syntax table terminal text textarea threading time tlapse trick tuple tutorial twoup ubuntu unicode unit urllib urllib2 variable wordgame wxpython






