3

I know this is simple but am unable to find this online. Using ArcMap 10.5 I want to drop the first digit of the three in a numeric column.. e.g., (023) where I want it (23). Which query can I use to make that happen?

1
  • 1
    Where are you wanting this? Do you want to update the column, or into a new column? Is it only zero or any number e.g. 123 becomes 23?
    – Midavalo
    Commented Nov 2, 2017 at 18:04

3 Answers 3

7
  1. Create a new Field with Text format
  2. on the new field use Field calculator and select python .
  3. double click the field that has numbers.
  4. Type [1:] after field name .

For example if your field name is test : !test![1:]

If you want to use Integer type of field directly, first convert the origin field to the string and then use the above steps:

str(!test!)[1:]

enter image description here

2

You can use python and the UpdateCursor. Im assuming your field is a text field since you have values starting with zero:

import arcpy
fc = r'C:\TEST.gdb\polygons123' #Change to match your data
field_name='Column123' #Change to match your data

with arcpy.da.UpdateCursor(fc,field_name) as cursor:
    for row in cursor:
        row[0]=row[0][1:]
        cursor.updateRow(row)
1

Adding a new field per @wetland is the easiest way to go, but only if the original field is a string/text. However, if for any reason you can't create a new field, or the original field is Short integer type, or you just want to modify the field values in place, you can copy and paste the following into the Geoprocessing -> Python window, replacing the layer name and the name of the field you want to modify.

cursor = arcpy.UpdateCursor("[layername]")
for row in cursor:
    orig_val = str(row.getValue("[fieldname]"))
    new_val = int(orig_val[1:])
    row.setValue("[fieldname]", new_val)
    cursor.updateRow(row)
del cursor

If you only want to drop the first number if it's a zero, you can use the following:

cursor = arcpy.UpdateCursor("[layername]")
for row in cursor:
    orig_val = str(row.getValue("[fieldname]"))
    if orig_val[0] == '0':
        new_val = int(orig_val[1:])
        row.setValue("[fieldname]", new_val)
        cursor.updateRow(row)
del cursor
1
  • Your code is very interesting. I edited my answer . Thanks
    – BBG_GIS
    Commented Nov 2, 2017 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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