AnsweredAssumed Answered

Concatenating Strings with Field Calculator and Python - dealing with NULLS

Question asked by cdspatial Champion on Nov 6, 2015
Latest reply on Aug 29, 2018 by

I have some addressing data that I would like to update and one of the tasks is to concatenate a new full street address field [ADDR1] by combining several of the component fields.  I know how to do this in VBScript, but figured this would be a good example to work out in Python, as I don't use Python often and have alot to learn.  My programming background is FORTRAN and BASIC, and in the years since those were popular hack and slash adapting code for AML/Avenue/VBA/VB.Net - so assume I know little about Python.


What is desired (psuedo-logic):



I'm using ArcGIS 10.2.1 and the data shown here is test data in a File Geodatabase feature class.


After poking around various Help articles, it appears that in Python the .format method in would work.  However, when I run it in Field Calculator the result looks good except "None" gets concatenated as text if the original field value was NULL (this issue doesn't come up with VBScript).  I'd like any values of NULL to instead just be blank - i.e. ignore them entirely.  For example, for the first record the desired outcome in ADDR1 is "224 D N CHURCH ST" not "224 D N CHURCH ST None".


Concatenation Python NULLS become None.png


One of the Python articles I found mentions the NULL issue:


Dealing with Null Values.jpg

Source:  Concatenating field values using Calculate Field | ArcGIS Blog


Is there a different way to do the concatenation in Python to achieve the desired outcome?  I'm trying to wrap my head around how Python approaches this, particularly in regards to using it in ArcMap in Field Calculator. 

  • I noticed some articles suggested casting all the fields to string to resolve the NULLS.  However, I haven't had any luck adding in str() in with the fields in the format statement shown.  It would just error out.  Would this need to be a separate line to do the casting?
  • Would a better approach be to use the Codeblock to run some sort of process to convert NULLS to blank before running the format method?  For example, adapt a process similar to this?


Source:  arcgis desktop - Calculate Field tool to calculate on null fields - Geographic Information Systems Stack Exchange


Lastly, can you recommend a good guide for beginners that explains how to use Python for these sort of issues?





Chris Donohue, GISP