2

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.

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

1 Answer 1

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) 
8
  • 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. Commented Apr 28, 2017 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? Commented Apr 28, 2017 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 Commented Apr 28, 2017 at 14:21
  • yes its a float numeric field Commented Apr 28, 2017 at 14:22
  • 1
    yes exactly we use commas instead of decimal points in numeric field Commented Apr 28, 2017 at 14:23

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.