Select Null Values from Field and Replace with Text - Field Calculator

3803
6
Jump to solution
08-14-2014 09:52 AM
AndreeaAmbrus
New Contributor III

This should've been an easy thing, but it gives me problems. I am trying to build a model and I want to use the Field Calculator to replace all the null vaules with a text. I'll do a series of append, and after each append I want to calculate the null values to be a certain text value (which I input). Here is the code that I am using:

def RemoveNULL(Name):

   if  Name is None:

     then return 'Basin'

else:

return Name

 

I am not very good at writing codes so I am not sure what is wrong here. When I run it, I get this:

Expected 'Then' Failed to execute (Calculate Field).

 

Any help would be appreciated. Thanks.

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

we will get this right after all..if you are using the Python parser, and ...if your field is called Name, then the field name in the lower section must be enclosed in exclamation marks

!Name!

View solution in original post

0 Kudos
6 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Your last two lines are indented improperly, they should be

if  Name is None:

  return 'Basin'

else:

  return Name

0 Kudos
AndreeaAmbrus
New Contributor III

Picture1.png

Thank you, I tried it, but I still get the same message " Expected 'Then' Failed to execute (Calculate Field)."

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

your first return statement has 2 spaces, your last one has only 1...spacing must be consistent

0 Kudos
JorgeOrellana
Occasional Contributor II

Also change your parser from VB to Python (at the top of the field calculator window)

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

we will get this right after all..if you are using the Python parser, and ...if your field is called Name, then the field name in the lower section must be enclosed in exclamation marks

!Name!

0 Kudos
AndreeaAmbrus
New Contributor III

It worked! Thank you!!!!!!! I guess it's time for me to start learning Python:)