python的新手,我有一个带lat / long的cvs文件,我正在尝试检索地址,如何将我的lat / long字符串传递给geolocator
with open('try.csv', 'rb') as f:
reader = csv.DictReader(f)
for row in reader:
geolat = row['pickup_latitude']
geolong = row['pickup_longitude']
# point = Point(float(row['pickup_latitude']), float(row['pickup_longitude']))
val1 = ("\""+geolat+", ")
val2 = (geolong+"\"")
val = val1 + val2
print val
# var returns "40.750912, -73.99102"
location = geolocator.reverse(val)
答案 0 :(得分:1)
geolocator.reverse
接受一个以逗号分隔的字符串作为其参数。
with open('try.csv', 'rb') as f:
reader = csv.DictReader(f)
for row in reader:
geolat = row['pickup_latitude'] # geolat is a string
geolong = row['pickup_longitude'] # geolong is a string
latlong = [geolat, geolong] # latlong is a list of two strings
val = ", ".join(latlong) # val is one comma-separated string
location = geolocator.reverse(val)
print(location)
当然,您可以牺牲可读性来削减所有中间步骤。
with open('try.csv', 'rb') as f:
reader = csv.DictReader(f)
for row in reader:
location = geolocator.reverse(", ".join([row['pickup_latitude'], row['pickup_longitude']]))
print(location)
Rembember,Python中的行缩进约定是4个空格。