NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Hi everyone!

I am trying to retrieve cities from zipcode_state. Here is the code:

Locations = pd.read_csv("geoloc1.csv", delimiter = ';')
Locations = Locations.drop_duplicates()
Locations['GEOLOC1'] = Locations['GEOLOC1'].str.rstrip() # Removing spaces at the right ot the nation name
Locations['CAP NAZIONE'] = Locations['GEOLOC1'].str.split('-').str[-1].str.strip() # Remove everything before -
Locations['CAP NAZIONE'] = Locations['CAP NAZIONE'].str.replace('_',' ') # Substitutes - with space 
Output = pd.DataFrame()

for index, row in Locations.iterrows():
cap = row['CAP NAZIONE'].split(" ",1)[0]
nazione = row['CAP NAZIONE'].split(" ",1)[1]
loca = geocode(query = row['CAP NAZIONE'], addressdetails = True, language = 'it,en')
    row['LOCATION'] = loca.raw['address']['city']
        row['LOCATION'] = loca.raw['address']['hamlet']
            row['LOCATION'] = loca.raw['address']['county']
            row['LOCATION'] = '_'

if nazione == 'ITALIA':
        row['REGIONE'] = loca.raw['address']['state']
Output = Output.append(row)

The problem is that fro certain zipcode_nazione it doesn't return the right city. For example: 23841_ITALIA it returns Avellaneda that is in Buenos Aires not in Italy.

How can I get the correct city? Is there something I am doing wrong or some more accurate method, package, library I can use?

Thanks, Carlotta.

asked 31 Mar '20, 17:10

Carlotta's gravatar image

accept rate: 0%

Nobody has added an address in Italy with that postcode to the OpenStreetMap data yet.

Right now returning a residential road in Argentia.

You already set language = 'it,en'. Try if it supports countrycodes = 'it' as well as filter and remove the "Italia" from the main query if possible. That will return no results, but it's slightly better than having the geocoder search in all countries.

OpenStreetMap has no central reporting tool for missing data. We often rely on people living the area to add data. I hope setting the countrycodes filter will return more results for your other postcodes.

permanent link

answered 31 Mar '20, 19:53

mtmail's gravatar image

accept rate: 27%


Update: I found the address of a local golf course with the postcode in their website and added it to OpenStreetMap. The Nominatim database updates its postcode database once per night (London time).

(31 Mar '20, 19:57) mtmail

Thank you a lot, I will try with countrycodes and see how it goes.

Thank you for adding this postecode to the OpenStreetMap website. How can I do it if I find other postecodes that are not in the OpenStreetMap data yet?

(01 Apr '20, 08:13) Carlotta

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 31 Mar '20, 17:10

question was seen: 2,196 times

last updated: 01 Apr '20, 08:13

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum