Python ArcMap Fill Empty Space in Attribute table

1251
4
11-21-2018 08:39 PM
RyanPhillips2
New Contributor

Hello,

I am trying to fill specific rows of data that have no data in them with a combination of data from other fields within the attribute table. I'm currently using the UpdateCursor command and I have this code worked out and it runs with no errors but, nothing happens.... The rows don't fill in with the data. 

with arcpy.da.UpdateCursor("Export_Output", ["SYM", "ZONE_SUBTY","Label","FLD_ZONE"]) as rows:
... for row in rows:
... if row[0] == "":
... row[2] = "row[3]“-”row[1]"
... row[0] = "SPECIAL"
... rows.updateRow(row)

Thank you! 

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus
if row[0] is None:
    row[2] = str(row[3] - row[1]"  # assuming row[3] and row]1] are numeric

I am assuming the noted comment on line 2.

Your incarnation of line 1 won't work unless there is a string in it.  If the field contains <null> values, then you have to test for None

JoeBorgione
MVP Emeritus

Ryan-  with your keen interest in arcpy, here is a little tip when working with cursors: you can create a variable to hold your list of attribute field names and get extra style points for it:

fields = ['SYM', 'ZONE_SUBTY', 'Label', 'FLD_ZONE']
with arcpy.da.UpdateCursor("Export_Output", fields) as rows:
... for row in rows:
...
...

BTW,  Dan's str() method is missing the closing paren- he did that just to see if I'd notice....   

That should just about do it....
DanPatterson_Retired
MVP Emeritus

good catch... I will leave it to see if others catch it

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Ryan Phillips‌, for future reference, the Python‌ place/space is where ArcPy questions usually get asked.