1

I want to delete . , # in attribute table using field calculator (VB Script or Python).

How can I remove these using this example address: N. First St., Unit #1 (I don't need city or state name)

I checked several websites, but I couldn't find the clear answer.

How to remove comma from combined fields which should be null?

http://www.geospatialanalyst.com/search/label/field%20calculator

  • 2
    Which field calculator are you using? ArcGIS for Desktop, QGIS and probably other GIS software have this tool. – PolyGeo Apr 1 '15 at 20:39
  • It's ArcGIS for Desktop 10.2.1 version – Ginny Apr 6 '15 at 14:36
3

Use the built-in str.translate(table[, deletechars]), but with None for the table argument (requires at least Python 2.6). E.g.:

'N. First St., Unit #1'.translate(None, '.,#')

shows:

'N First St Unit 1'

Or for ArcGIS' calculator, this can be a one-liner:

!yourField!.translate(None, '.,#')
  • Simple, I like this one. – ianbroad Apr 1 '15 at 21:47
1

Use python to calculate values in new field:

filter(lambda x: x not in ".,#", !yourField!)
1

in the python code block:

import re

def strip(value):
    return re.sub('[.,#]','',value)

and then in the field calculator:

strip(!fieldname!)
1

And another way.

Python Pre-Logic Script Code:

def remove(text):
    for char in [".", ",", "#"]:
        if char in text:
            text = text.replace(char, "")
    return str(text)

Bottom part:

remove(!yourField!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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