我試圖使用geopy通過使用從github下載的一些代碼進行地理編碼地址。 但錯誤的代碼是str obj不支持geocode_addresses address_dict["error"] = ""
中的項目分配? 爲什麼我得到這個錯誤。下面是代碼。錯誤:'str'對象不支持python中的項目分配
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";
請提供更多詳細信息,具體來說,是什麼*是*'address_dict'。據推測這是一個「字典」,但錯誤表明否則。 –
'address_dict'似乎是一個'str' - 這意味着您需要查看代碼中調用geocode_addresses的位置,以找出爲什麼它是可迭代的字符串。 – mgilson
你能提供一個示例數據集嗎? – zmo