I have a very large dataset in ArcMap 10.6 and I would like to create a subset that selects only rows that have specific attributes (some of them with special characters) from a field that in my case has a list of multiple codes and words.


Let's say that I want a dataset that contains only the rows with the code BMX-3000 and INDEX-AB, but not other values.


Can anybody suggest me a relevant code query or model creation steps?

1 Answer 1


Try this python function in Field Calculator:

def replaceValue(attr):
  keep = ['BMX-3000', 'INDEX-AB', 'otherValue']
  for val in keep:
    found = attr.find(val)
    if found > -1:
      return val
  if found == -1:
    return attr

function call =


  • Hi artwork21, thanks for your answer. Where do I type "function call = replaceValue(!fieldNameToCheckAgainst!)" ? Commented Sep 9, 2019 at 8:57
  • When you open the tool click the Pre Logic checkbox, the code goes in the large top box and the function call goes in the smaller bottom one. Make sure you select the python parser option too.
    – artwork21
    Commented Sep 9, 2019 at 12:26
  • What if some rows have: BMX-3000, NAB-H, INDEX-AB. and I want to obtain: BMX-3000, INDEX-AB? The code currently deletes INDEX-AB if it is in the row after BMX-3000, . Commented Sep 13, 2019 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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