I'm new to python and trying to write a python script using the field calculator in ArcMap for a specific field in an attribute table that will replace some of the values in the field but leave the other values as they are within the table.

For example: ""fourth" must be changed to "4th" whereas "Neilston" should remain as it is in the field. The field in the table looks like this:

enter image description here

The python script used in the codeblock looks like this:

def streetNUM(field):

   if field == "fourth":

      field.replace ("fourth","4th")

   elif field == "fifth":

      field.replace ("fifth","5th")
      return field

And then in the box below the codeblock I have:


Nothing seems to change and I get an error code saying:

Field is not nullable [FULLNAME]

Any suggestions as to where I may be going wrong with my code?

3 Answers 3


You have a couple things going on in your IF and ELIF conditions:

 if field == "fourth":

This line will only be true if the value in your field is "fourth", in lowercase. "Fourth" wouldn't satisfy this condition, neither would "Fourth St." or "fourth street".

 field.replace ("fourth","4th")

You need to prefix this with return. Right now this line will replace "fourth" (again, only if it's lowercase) with "4th", but you need your function to return that value.

  • I made the changes you suggested and when I run it again in field calculator, I don't get any error messages, but none of the values change in the table. The word "Fourth" still shows as "Fourth" and not "4th".
    – Bec
    Oct 27, 2017 at 21:18
  • @Bec If you're trying to do this on an existing field, you'll need to use an Update Cursor to do it. I'm pretty sure Field Calculator can't be used to update values in an existing field at the same time that field is being used as the source for the calculation. You could create a new text field in your attribute table (FULLNAMEv2 or something) and do the field calculation there.
    – Dan C
    Oct 27, 2017 at 21:27
  • I know it can be done outside of using the codeblock in field calculator as I have seen that from a classmate who typed in !FULLNAME!.replace("Fifth","5th").replace("Sixth","6th")...going through all the variables that needed changed and got the expected results. Our instructor is expecting this to be done via a python script in the codeblock though for the "FULLNAME" field. There is no mention of creating a new text field.
    – Bec
    Oct 27, 2017 at 21:36

With help from another forum, by changing:

if field == "Fourth":


if "Fourth" in field: 

and then the previous suggestion of adding the prefix return in front of


the field calculator tool ran as expected.

def LyrLineTypeCatEye(field):

   if  "01" in filed:
     return field.replace("01","unic")

    return field‍‍‍‍‍‍‍‍‍‍


I did exactly like you said and I don't understand why it's not working!

  • Welcome to Geographic Information Systems! If you have a NEW question, please ask it by clicking the Ask Question button. If you have sufficient reputation, you may upvote the question. Alternatively, "star" it as a favorite and you will be notified of any new answers.
    – Ian Turton
    May 27, 2021 at 8:37

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.