I need some help with an assiment:
Write a function that opens the file Exports2012.csv
and returns a
map for the 10-top products among the Estonian exports. The map should
associate the name of the product with its corresponding value in USD.
For convenience, you should covert the string '$2,268,911,208.49'
into a
float value.
Example of CSV:
#,HS,Name,Value (USD),Percent
1,8517,Telephones,"$2,823,450,843.60",15.38%
2,2710,Refined Petroleum,"$2,124,413,818.52",11.57%
3,8703,Cars,"$371,092,090.84",2.02%
4,7204,Scrap Iron,"$331,463,406.48",1.81%
5,8544,Insulated Wire,"$319,352,873.32",1.74%
6,4011,Rubber Tires,"$242,977,533.70",1.32%
7,8708,Vehicle Parts,"$241,059,109.78",1.31%
8,8429,Large Construction Vehicles,"$239,589,588.65",1.31%
9,4407,Sawn Wood,"$238,358,904.17",1.30%
10,4418,Wood Carpentry,"$237,521,163.59",1.29%
11,7210,Coated Flat-Rolled Iron,"$213,137,606.81",1.16%
12,9404,Mattresses,"$208,042,615.08",1.13%
13,4403,Rough Wood,"$206,112,209.11",1.12%
14,9403,Other Furniture,"$202,900,185.49",1.11%
15,8504,Electrical Transformers,"$202,856,149.28",1.10%
I know how to extract 2. and 3. columns, but I'm stuck at this point.
import csv
f= open('EstonianExports2011.csv', 'rb')
archive = csv.reader(f, delimiter=',')
arch_dict = {}
arch_dict = {row[2]: row[3]for row in archive}
print arch_dict
I'd appreciate any help.