1

I am a bit new for the arcpy. I have a database table so I can't use field calculator. so I would like to use Python script for solving the issue.

import arcpy
... # Your input feature class
... table = r'D:\werk_map.gdb\test_gw_bsl'
... # Start an update cursor and change values from 0 to 100 in a field called "your_field"
... with arcpy.da.UpdateCursor(table, "Thickness") as cursor:
...     for row in cursor:
...         if row[0] == "0,1":
...             row[0] = "0,5"
...         cursor.updateRow(row)

enter image description here

I just want to replace all “0,1” values in the thickness field with “0,5”. The above written arcpy script is running without error but not changing the values in the table. I think may be it has do something with the comma in the field value.

  • Welcome to GIS SE! Thank you for taking the new user tour. – Midavalo Apr 28 '17 at 13:31
  • After your for statement try: print row[0] to see what is actually being picked up by the cursor – GISKid Apr 28 '17 at 14:20
2

First I don't see why you can't do this using the Field Calculator - it works on Database Tables as well as Feature Classes and Layers.

Now onto your script - you are very close. Your cursor if is checking for "0,1" and wanting to replace with "0,5" - the quote-marks around it means it is looking for text but your values are numbers, stored in a numeric type field. Python won't find text in a numeric field.

Also, because of how python treats commas, you will need to use a decimal point . in your code (it won't affect how it is stored in your table):

import arcpy
    # Your input feature class
    table = r'D:\werk_map.gdb\test_gw_bsl'
    # Start an update cursor and change values from 0 to 100 in a field called "your_field"
    with arcpy.da.UpdateCursor(table, "Thickness") as cursor:
        for row in cursor:
            if row[0] == 0.1:
                row[0] = 0.5
            cursor.updateRow(row)
  • Thank you, Midavalo for you reply. i tried your suggestion but its not working. The field thickness accepts only ", " commas instead of "." decimal points( float nummer). The field calculator is greyed out. I think its a relational database table. – Ram Apr 28 '17 at 14:17
  • Just curious as to how you know its a numeric field? I would have thought since it contained a comma that it would have to be text? – GISKid Apr 28 '17 at 14:20
  • 1
    @GISKid The values are right-aligned in the screenshot. Numbers are (usually) right-aligned, text is left-aligned. I could be wrong though, other countries/regions may have the left/right align settings different than what I use – Midavalo Apr 28 '17 at 14:21
  • yes its a float numeric field – Ram Apr 28 '17 at 14:22
  • 1
    yes exactly we use commas instead of decimal points in numeric field – Ram Apr 28 '17 at 14:23

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.