I recognize similar questions have been asked but I have yet to see what my code is lacking in any of their answers.
I am trying to use the code below to periodically update attributes in a Feature Class that is often added to during our survey. The goal is every time the 'SBP Anomaly' or 'BS Anomaly' is present in the 'Target_Typ' column a sequential integer will be marked in the 'SBP_Num' and 'BCKSCTR_Nu'(Better name forthcoming) columns respectively.
The first two 'for loops' under my Update Cursor are operating correctly, however, the third doesn't update/populate its target fields when the conditions are met.
import arcpy
fc = arcpy.GetParameterAsText(0)
fields = ['Target_num','Target_Typ','WCA_Label', 'BCKSCTR_Nu', 'SBP_Num' ]
i = 1
x = 1
s = 1
with arcpy.da.UpdateCursor(fc,fields) as rows:
for y in rows:
y[0] = x
x+=1
rows.updateRow(y)
for row in rows:
if row[2] != None and row[1] != 'SBP Anomaly':
row[1] = "WC Anomaly"
else:
row[1] = "BS Anomaly"
rows.updateRow(row)
for TypeCount in rows:
if row[1] == 'SBP Anomaly':
row[4] = int(s)
s += 1
elif row[1] == 'BS Anomaly':
row[3] = int(i)
i += 1
else:
pass
rows.updateRow(TypeCount)
del rows
An image of the attribute table I am trying to manipulate is included also for reference. I have made sure the Target fields for third 'for loop' are set up as the correct object type: short integers (at least I think that's appropriate ) and not strings so they should take the integers i/s. I have tried them as strings and Long integers, and even float one time.
Update based on some suggestions from various users. Tried this code and still no luck.
import arcpy
fc = arcpy.GetParameterAsText(0)
fields = ['Target_num','Target_Typ','WCA_Label', 'BCKSCTR_Nu', 'SBP_Num' ]
i = 1
x = 1
s = 1
with arcpy.da.UpdateCursor(fc,fields) as rows:
for row in rows:
row[0] = x
x+=1
if row[2] != None and row[1] != 'SBP Anomaly':
row[1] = "WC Anomaly"
else:
row[1] = "BS Anomaly"
if row[1] == 'SBP Anomaly':
row[4] = s
s += 1
elif row[1] == 'BS Anomaly':
row[3] = i
i += 1
else:
pass
rows.updateRow(row)
Also per one users comment, A more detailed description of what I want to acheive. Entries in this feature class are usually manually entered via creating features, i.e. picking them based on data available. When that happens several attributes need to be update manually.
-The Target_Num or Target number needs to be entered in sequential order. That hasn't been a problem so much.
-The 'BS' and 'SBP' anomalies will have be populated in the Target Type column, however, the WS anomalies need to be manually input in that column. These are added from another software program so that particular attribute needs to be populated. The idea with this code is that it takes another column attribute, one that only exists for the WC anomaly, and when there is data present, set the Target type to 'WC Anomaly'. Elsewise, Make it a Backscatter Anomaly. The only prohibitive condition with this is if there if Target Type is already listed as a 'SBP Anomaly', which should be left alone.
-Lastly, if the Target type is equal to SBP or BS anomaly, then it should populate the SBP/BSCKTR_Num column. This is to keep a running tally of how many of each targets there is.
TypeCount
variable was never modified.