I want to replace the all the -9999 values in my attribute table with 0.

Does anyone know an easy way to do this?

enter image description here


You can run this code inside the Python window. I assume that all those columns with -9999 are of numeric type:

with arcpy.da.UpdateCursor('pure_proj', "*") as cur:
    for feat in cur:
        for i in range(len(feat)):
            if feat[i] == -9999:
                feat[i] = 0

What we are doing here:

  1. Create a cursor connection to the underlying feature class using da.UpdateCursor.

  2. As we got all the fields, we need to check every value in each row. This could be done using the enumerate or range.

  3. If -9999 is found, we set the value for this particular row's column to be 0. Afterwards we update this particular row using the updateRow() method.

| improve this answer | |
  • 1
    Did it work for you? I've updated the answer to include more details on the workflow to help you get started. – Alex Tereshenkov Feb 23 '18 at 14:57
  • 2
    Yes, it worked out. I appreciate the explanation you did beneath. – Lutz Feb 23 '18 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.