下面的代码执行时耗时较长。
for index,row in d_airbnb.iterrows(): #Loop for para varrer cada linha.
latitude = row['latitude']
longitude = row['longitude']
location = geo_locator.reverse((latitude, longitude),language='en', exactly_one=True,timeout=5) #Usamos o metodo geolocator.reverse() para descobrir se cada zipcode é válido.
address = location.address
if row['neighbourhood'] not in address:
d_airbnb.at[index, 'zipcode'] = '00000' #Caso o zipcode não corresponder ao bairro que o locator.reverse me forneceu pela API, então o zipcode é invalido e inconsistente. Por isso trocamos por "00000".
我尝试将超时增加到 2 秒,但仍然需要很长时间并产生一些超时错误:
WARNING:urllib3.connectionpool:Retrying
(Retry(total=1, connect=None, read=None, redirect=None, status=None))
after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443):
Read timed out. (read timeout=1)")'
这是什么原因造成的,如何治疗?
还有其他方法可以更快地检查这些邮政编码吗?我的数据集中有 70'000 行和 29 列。