2017-12-15 5 views
-3
import googlemaps 
from datetime import datetime 
import csv 
gmaps = googlemaps.Client(key='******************') 

input = open('geocodes.csv','r') 
output = open('geocodesres.csv', 'w') 

try: 

    reader = csv.reader(input) 
    writer = csv.writer(output) 



for row in reader: 

    print(row) 
    coordinates1, coordinates2 = [float(c) for c in row] 


    my_location = gmaps.reverse_geocode(coordinates1,coordinates2) 

    writer.writerow(my_location) 

finally: 
    input.close() 
    output.close() 

これは私がエラーであるとValueErrorが:浮いているように文字列を変換できませんでした:「coordinates1」

ValueError: could not convert string to float: 'coordinates1'

入力ファイルは、ジオコードするための経度及び緯度情報を含みます。これは、そこからの抜粋である:

coordinates1 coordinates2 
-74.0064354 40.6548713 
-73.98696542 40.75470191 
-73.99653 40.750742 
-73.957836 40.7222889 
-73.86747837 40.89872539 
-74.0064354 40.6548713 
-73.92064 40.81161 
+0

入力ファイルからスニペットを投稿しますか?あなたのエラーから – chrisz

+0

coordinates1 \t coordinates2 -74.0064354 \t 40.6548713 -73.98696542 \t 40.75470191 -73.99653 \t 40.750742 -73.957836 \t 40.7222889 -73.86747837 \t 40.89872539 -74.0064354 \t 40.6548713 -73.92064 \t 40.81161 – shinoda

+0

それがあるかのように、それはそうです'coordinates1'をfloatに変換しようとしています。 – chrisz

答えて

0

nextを使用して、文字列coordinates1 coordinates2との最初の行を消費:

reader = csv.reader(input) 
next(reader) 

それはフロートに変換することができないからです。

関連する問題