I'm trying to create a function that imports a csv file which holds records for population per year (as strings). It imports a file which has the year in the 3rd column and the population count in the 4th.
It should remove the decimal point '.' and display the resulting population.
16122.83
16223.248
should become
1612283
16223248
When I try to do this I get: in print_population_list year, population = row[2], float(row[3]) ValueError: could not convert string to float: POP. This is my code:
import csv
file = csv.reader(open(filename))
year, population = 0, 0
for row in file:
year, population = row[2], float(row[3])
print year,":", population,
To do this I figured it should first be converted to a float and be multiplied by the highest number of decimal places, after which all zero's at the end should be removed (since the data doesn't all have the same number of decimal places). But I'm stuck at the float conversion.