1

I would like to clean up fields that contain repeated "Street Names". As seen below, I have fields "Name_From" and "Name_To". These fields sometimes repeat the same name (highlighted). I would like to remove these repeated street names.

As seen below in the Name_From field, the highlighted record says "Preller & Preller". I would like to end with only "Preller". ("Preller & Preller" becomes only "Preller".)

This repetition is also present in the Name_To field.

.enter image description here

  • 1
    @Dean van den Heever, I don't see how it is a duplicate. The first row is from: Preller&Preller and to: President&President; the second is from: Steyn&Steyn and to: Preller&Preller. Is it a duplicate since Preller&Preller shows both on from and to in different rows which makes no sense at all? or is Preller&Preller, etc. the duplicate, and you would like it to be: Preller instead..? – dof1985 Mar 7 '15 at 12:33
  • Yes. The Preller & Preller is the duplicate. I would like to be only left with one Preller text. This duplication of records are present in both the Name_from and Name_to fields respectively. – Dean van den Heever Mar 7 '15 at 12:52
1

If your values always have a charater between two street names (e.g. "&"), you may use this python function in field calculator:

def updateField(field):
  found = field.find('&')
  if found > -1:
    firstStreetName = field.split(' ')[0]
    secondStreetName = field.split(' ')[2]
    if firstStreetName.upper() != secondStreetName.upper():
      return field
    else: return firstStreetName
  else: return field

updateField(!myField!)

0

This code should do the job. You should run it separately for each field. Use python in field calculator, and paste this into your Code Block:

def Dupli(field, char="&"):
  charLoc = field.find(char)
  strLeft = field[:charLoc].strip()
  strRight = field[charLoc+1:].strip()
  if (strLeft == strRight):
    return(strRight)
  else:
    return(field)

and paste this as your field calculator value

Dupli('same field name',"&")

Notice that you should use the same field name, i.e. if you try to remov duplicates from the 'FROM_NAME' field, and the separator that is used to separate names is '&', your code will look as follows:

 Dupli(!FROM_NAME!,"&")

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.