Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow performance for Portugal (PT) #53

Open
volkangumuskaya opened this issue Oct 1, 2021 · 1 comment
Open

Slow performance for Portugal (PT) #53

volkangumuskaya opened this issue Oct 1, 2021 · 1 comment

Comments

@volkangumuskaya
Copy link

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 ('')
@volkangumuskaya
Copy link
Author

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant