You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I am querying latitude and longitude from the postcodes of 26 countries. When I made a test run where there are 10 rows for each country, Portugal (PT) takes much longer to process. For reference, all other countries run in the range of 1-3 seconds, while for Portugal this ranges in 30-40 seconds.
I'm not experienced in Python much, so probably my coding is not the most efficient but it is odd that one country stands out (Suggestions to improve the code below is most welcome).
for country_code in np.unique(df.COUNTRY_VALUE):
print(country_code,len(df[df.COUNTRY_VALUE==country_code]))
start_time = time.time()
nomi = pgeocode.Nominatim(country_code)
df.loc[df.COUNTRY_VALUE==country_code,'LAT']=df.POSTCODE.apply(get_city).latitude
df.loc[df.COUNTRY_VALUE == country_code, 'LON'] = df.POSTCODE.apply(get_city).latitude
print("--- %s seconds ---" % (time.time() - start_time))
def get_city(code):
try:
x=nomi.query_postal_code(code)
return x
except:
return ('')
The text was updated successfully, but these errors were encountered:
As an alternative solution, I downloaded the txt files and used them directly from this website. It is much faster but static. Website is http://download.geonames.org/export/zip/
Hi,
I am querying latitude and longitude from the postcodes of 26 countries. When I made a test run where there are 10 rows for each country, Portugal (PT) takes much longer to process. For reference, all other countries run in the range of 1-3 seconds, while for Portugal this ranges in 30-40 seconds.
I'm not experienced in Python much, so probably my coding is not the most efficient but it is odd that one country stands out (Suggestions to improve the code below is most welcome).
The text was updated successfully, but these errors were encountered: