2

I am trying to move field entries down by 1 in an attribute table, between a certain row spread. I would like to move all the entries in the 'key biomechanical features' column down by 1 row between row x and row y ('Down' meaning the highlighted key biomechanical field entry in the image moving down to the field below it). I would like all the other columns to stay in their same place, and I would like the other entries in the 'key biomechanical features' column that are not in the row spread to stay in their respective location.

enter image description here

Is there a way to do this using the field calculator and Python parser of ArcGIS Pro?

1
  • The description for the "fair" should move down and describe "dead"? Aug 20, 2021 at 13:05

2 Answers 2

3

In python console:

import arcpy
fc = r'C:\GIS\ArcMap_default_folder\Default.gdb\fs_riks_Buffer'
field_to_move = r'buildingID'

#Create a list of all values
sql = """ORDER BY {0} ASC""".format(arcpy.AddFieldDelimiters(fc, arcpy.Describe(fc).OIDFieldName))
data = [f[0] for f in arcpy.da.SearchCursor(in_table=fc, field_names=field_to_move, sql_clause=(None, sql))]
data.insert(0, -1) #Change -1 to whatever you want to start with. Can be data[-1] if you want the last value
givedata = iter(data)

#Use it to update the field
with arcpy.da.UpdateCursor(in_table=fc, field_names=field_to_move, sql_clause=(None, sql)) as cursor:
    for row in cursor:
        row[0] = next(givedata)
        cursor.updateRow(row)

enter image description here

3

Use field calculator and create a copy of the field (let's call it key_biomechanical_features_2) with the following expression. It requires a field with unique id, corresponding to the $id (this field is here called id) that defines the order/sequence. Change key_biomechanical_features (twice) to the name of your initial field. Copy the result back to your initial field (see below for details).

if (
    "id" >=3 and "id" <= 7,
    attribute (
        get_feature_by_id (@layer, $id-1),
        'key_biomechanical_features'
    ),
    "key_biomechanical_features"
)

Screenshot: from id 3 to id 7, it takes the value from the last entry of the key_biomechanical_features - see the initial values in the 3rd column, the result in the last column: enter image description here

By the way: If you want to have the result back in the original field rather than in a copy of the field, copy the created key_biomechanical_features_2 back to the initial key_biomechanical_features. In the field calculator, check Update existing field, select the initial field and as expression, enter the name of the new (copied) field.

If you do it in one step (by updating an existing field), all the moved entries will have the same value, the one of the first entry as it takes first updates the first entry, than takes this value for the next one and so on.

Your Answer

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

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