【发布时间】:2019-10-12 16:22:05
【问题描述】:
python 新手。我在 python 中使用 pygeocodio 库
API_KEY = "myapikey"
from geocodio import GeocodioClient
client = GeocodioClient(API_KEY)
addresses = client.geocode("21236 Birchwood Loop, 99567, AK")
addresses.best_match.get("accuracy")
Out[61]: 1
addresses.best_match.get("accuracy_type")
Out[62]: 'rooftop'
但是,如果我想遍历数据框(example.csv):
import pandas as pd
customers = pd.read_csv("example.csv")
for row in customers.iterrows():
addresses = client.geocode(row)
addresses.best_match.get("accuracy")
我收到一个错误:
File "C:\Users\jtharian\AppData\Local\Continuum\anaconda3\lib\site-packages\geocodio\client.py", line 58, in error_response
raise exceptions.GeocodioDataError(response.json()["error"])
GeocodioDataError: Could not geocode address. Postal code or city required.
example.csv 的代表:
21236 Birchwood Loop, 99567, AK
1731 Bragaw St, 99508, AK
300 E Fireweed Ln, 99503, AK
4360 Snider Dr, 99654, AK
1921 W Dimond Blvd 108, 99515, AK
2702 Peger Rd, 99709, AK
1651 College Rd, 99709, AK
898 Ballaine Rd, 99709, AK
23819 Immelman Circle, 99567, AK
9750 W Parks Hwy, 99652, AK
7205 Shorewood Dr, 99645, AK
为什么我会收到此错误?
【问题讨论】:
-
你的数据框只有一列吗?
-
是的,只有一栏 @Buckeye14Guy
-
for index,row in df.iterrows(): client.geocode(row.values[0])还要查看数据帧的apply方法。iterrows返回索引和行内容的元组。所以你没有将预期的参数传递给地理编码 -
@Buckeye14Guy 我是 python 新手。该行已运行,但我如何使用它为每一行运行addresses.best_match.get("accuracy")?