Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a shapefile British Columbia with postal codes. The attribute table gives the codes with no spaces, eg V6P2A8. I am trying to join a csv file by postal code (the key I am using). My csv file has postal codes with a consistent space, eg V6P 2A8. Naturally the join doesn't work because of that space.

How can I either remove the space?

share|improve this question
QGIS supports regexp_replace…… – Mapperz Jul 16 '13 at 19:25
+1 for regex! Absolutely unbelievable what you can do with them. Should be easy to write a script that does the same for ArcMap... – Paul Jul 16 '13 at 22:01

This is easy to remedy using Python. If you are in ArcGIS, you can simply use Python in a field calculator to strip the space from the field.

The code would look something like:

!post_code!.strip(" ")

which will remove the space in the postal code field. You can also do this in raw Python, but you would have to read in your csv file, make the change, and write a new one.

Alternatively, you could open your csv in Excel and use the Substitute function to replace the space with nothing. For example, to strip the space from a postal code in column A1, you would type =SUBSTITUTE(A1," ", "") in the output field. Then, just replace the original post code column with the new one.

share|improve this answer
Unfortunately opening the CSV file corrupts it for uploading to Access for example. By opening it in Excel it strips out 0s, eg, 05 becomes 5. – Nicky Day Mar 16 at 9:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.