Field calculator expression error

1224
1
02-27-2020 03:08 PM
AlexandriaSpofford
New Contributor

I am currently going through Chapter 7 of Getting to Know ArcGIS Pro called Geoenabling Your Project.

I am in part A on step 9. I have taken the following steps:

Open the community housing project

Add the table for household_income

Join the household_income table to the la_census_tracts

Open fields view and create a new field for AMI (Area median income) as a double, numeric, 2 decimal places

Attempt to calculate field for AMI using HHIncome (household_income)

Here is where I am stuck. The instructions say to enter

! household_income.csv.HHIncome! / 56241 * 100

When I click run it takes about 6.5 minutes. I receive an error message a few minutes in which says:

Warning 002858: Certain rows set to NULL due to error while evaluating python expression: TypeError: unsupported operand type(s) for /: 'NoneType' and 'Int'

Looking at the AMI column, the entire thing reads <null>

I have tried entering others values for it to evaluate, such as setting them all to 6. It eventually failed with an error saying "Something unexpected cause the tool to fail." and "General function failure" while still filling in most of the values to 6, but leaving some at the end of the table as <null>

I also tried using the python box but I am not familiar enough with the software to get much out of that. 

I also looked at the data in the household_income file and found that several HHIncome read as " - " in the excel sheet which translated into ArcGIS Pro as <null> . I am not sure if this has to do with the problem. Others I know have used the same file and not had this problem.

Thanks in advance for any advice!

0 Kudos
1 Reply
JoshuaBixby
MVP Esteemed Contributor

SQL NULL get translated to Python None, and you can't do mathematical operators between a numeric type and None.  For example, None + 2 will generate a similar error:

>>> None + 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
>>>

Is the field name really household_income.csv.HHIncome ?  Geez, that is ugly.

It appears you have NULL values for some of your fields, which you confirm at the end of your post.  In situations like this, you either need to have your expression account for an address the possibility of None/NULL, or you need to select all None/NULL records first.  I recommend for a beginning using Select Layer By Attribute to make a selection (IS NOT NULL) and then run the field calculator.