Skip to main content
added 62 characters in body
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 188

Use da.UpdateCursor instead of Field Calculator, it is more versatile and easier to use and you can pass the sql statement to only update "selected" rows:

import arcpy

fc = r"C:\Automation\Categories\Coal\Coal_automation.gdb\CLAIMS"
fieldname = "Claim_Spend_in_£"

sql = """{0} = ''""".format(arcpy.AddFieldDelimiters(fc,fieldname))

with arcpy.da.UpdateCursor(fc,fieldname,sql) as cursor:
    for row in cursor:
        row[0] = 'Unrecorded'
        cursor.updateRow(row)

If###If you want to use Field Calculator on a layer: A selection cant be made on a feature class, it has to be a layer. You can create a layer usewith MakeFeatureLayer, then pass 'lyr' to calculate field:

sql = """{0} = ''""".format(arcpy.AddFieldDelimiters(fc,fieldname))
arcpy.MakeFeatureLayer_management(in_features=fc, out_layer='lyr', 
                                 where_clause=sql)
...

Use da.UpdateCursor instead of Field Calculator, it is more versatile and easier to use and you can pass the sql statement to only update "selected" rows:

import arcpy

fc = r"C:\Automation\Categories\Coal\Coal_automation.gdb\CLAIMS"
fieldname = "Claim_Spend_in_£"

sql = """{0} = ''""".format(arcpy.AddFieldDelimiters(fc,fieldname))

with arcpy.da.UpdateCursor(fc,fieldname,sql) as cursor:
    for row in cursor:
        row[0] = 'Unrecorded'
        cursor.updateRow(row)

If you want to create a layer use MakeFeatureLayer, then pass 'lyr' to calculate field:

sql = """{0} = ''""".format(arcpy.AddFieldDelimiters(fc,fieldname))
arcpy.MakeFeatureLayer_management(in_features=fc, out_layer='lyr', 
                                 where_clause=sql)
...

Use da.UpdateCursor instead of Field Calculator, it is more versatile and easier to use and you can pass the sql statement to only update "selected" rows:

import arcpy

fc = r"C:\Automation\Categories\Coal\Coal_automation.gdb\CLAIMS"
fieldname = "Claim_Spend_in_£"

sql = """{0} = ''""".format(arcpy.AddFieldDelimiters(fc,fieldname))

with arcpy.da.UpdateCursor(fc,fieldname,sql) as cursor:
    for row in cursor:
        row[0] = 'Unrecorded'
        cursor.updateRow(row)

###If you want to use Field Calculator on a layer: A selection cant be made on a feature class, it has to be a layer. You can create a layer with MakeFeatureLayer then pass 'lyr' to calculate field:

sql = """{0} = ''""".format(arcpy.AddFieldDelimiters(fc,fieldname))
arcpy.MakeFeatureLayer_management(in_features=fc, out_layer='lyr', 
                                 where_clause=sql)
...
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 188

Use da.UpdateCursor instead of Field Calculator, it is more versatile and easier to use and you can pass the sql statement to only update "selected" rows:

import arcpy

fc = r"C:\Automation\Categories\Coal\Coal_automation.gdb\CLAIMS"
fieldname = "Claim_Spend_in_£"

sql = """{0} = ''""".format(arcpy.AddFieldDelimiters(fc,fieldname))

with arcpy.da.UpdateCursor(fc,fieldname,sql) as cursor:
    for row in cursor:
        row[0] = 'Unrecorded'
        cursor.updateRow(row)

If you want to create a layer use MakeFeatureLayer, then pass 'lyr' to calculate field:

sql = """{0} = ''""".format(arcpy.AddFieldDelimiters(fc,fieldname))
arcpy.MakeFeatureLayer_management(in_features=fc, out_layer='lyr', 
                                 where_clause=sql)
...