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 = x x+=1 rows.updateRow(y) for row in rows: if row != None and row != 'SBP Anomaly': row = "WC Anomaly" else: row = "BS Anomaly" rows.updateRow(row) for TypeCount in rows: if row == 'SBP Anomaly': row = int(s) s += 1 elif row == 'BS Anomaly': row = 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 = x x+=1 if row != None and row != 'SBP Anomaly': row = "WC Anomaly" else: row = "BS Anomaly" if row == 'SBP Anomaly': row = s s += 1 elif row == 'BS Anomaly': row = 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.