AnsweredAssumed Answered

How to check for duplicates in two fields of multiple rows then change a value

Question asked by matthowe17 on Jun 23, 2020
Latest reply on Jun 23, 2020 by bixb0012

I have a feature class with many rows representing wells. Each well record has two particular fields that I am interested in; FIELD and TOT_REC_RES_MMBOE. In some cases the value of field name and volume are the same e.g. Record 1: Well A, 500, Record 2: Well A, 500. I would like to look for duplicates of these two fields then set the volume field of only the duplicates to 0. If Well A, 500 was unique the volume would stay at 500. In summary I need to set the volume field for each duplicate found to 0 but keep the first record as the current volume, 500 in the example. In the code below, I'm using an update cursor to get the volume values from a fields feature class so wondered if I could do the duplicate section here.

src_field_list = ["FIELD", "IN_OIL_EQUIV_MMB"]
value_dict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(field_lyr, src_field_list)}
with arcpy.da.UpdateCursor(wells_temp, tar_field_list) as cursor:
for row in cursor:
  key_val = row[0]
  if key_val in value_dict:
   row[1] = value_dict[key_val][0]
  if row[1] is None: # Set the volume null values to 0 so they're not skipped in the well orders
   row[1] = 0
  if row[2] is None:
   row[1] = 0
del value_dict
del cursor