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?
3 Answers
- Create a new Field with Text format
- on the new field use Field calculator and select python .
- double click the field that has numbers.
- 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:]
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)
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
123
becomes23
?