我正在尝试通过使用从 github 下载的一些代码来使用 geopy 对地址进行地理编码。但是代码的错误是str obj不支持项目分配geocode_addresses address_dict["error"] = ""
?为什么我会收到这个错误。下面是代码。
if __name__ == '__main__':
csv_file = 'nr-fixedNew.csv'
with open(csv_file, 'rb') as csvfile:
for row in csvfile.readlines():
df = pd.read_csv(csv_file)
address = df.ADDRESS
geocoded = geocode_addresses(address)
write_csv(output_file, geocoded)
def geocode_addresses(address_dicts):
geocoder = geocoders.GoogleV3()
for address_dict in address_dicts:
address_dict["error"] = ""
try:
time.sleep(1)
address, (lat, lon) = geocoder.geocode(address_dict["fulladdress"])
address_dict["fulladdress"] = address
address_dict["latitude"] = lat
address_dict["longitude"] = lon
except ValueError as e:
address_dict["error"] = e
return address_dicts
数据集示例
SEX,PROGRAMME,ADDRESS
M,2,"J6855, JALAN LMBAH KESANG 1/1-3,77378 MERLIMAU, MELAKA";