1 import arcpy 2 import numpy 3 from arcpy import da 4 5 def GetFieldUniqueValue(inTable,inField): 6 value_list=[] 7 rows=arcpy.da.SearchCursor(inTable,inField) 8 for row in rows: 9 if row[0] not in value_list: 10 value_list.append( str(row[0]).decode('utf-8') ) 11 del row 12 del rows 13 return value_list 14 15 def GetDuplicateValue(inTable,inField): 16 dic={} 17 rows=arcpy.da.SearchCursor(inTable,inField) 18 for row in rows: 19 if row[0] in dic.keys(): 20 dic[row[0]]=dic[row[0]]+1 21 else: 22 dic[row[0]]=1 23 del row 24 del rows 25 for key,value in dic.items(): 26 if value==1: 27 del dic[key] 28 return dic 29 30 def GetFieldMode(inTable,inField): 31 dic=GetDuplicateValue(inTable,inField) 32 lst=[value for key,value in dic.items()] 33 num=max(lst) 34 modeList=[] 35 for key,value in dic.items(): 36 if value==num: 37 modeList.append(key) 38 return modeList 39 40 def GetFieldValueList(inTable,inField): 41 value_list=[] 42 rows=arcpy.da.SearchCursor(inTable,inField) 43 for row in rows: 44 value_list.append(row[0]) 45 del row 46 del rows 47 return value_list 48 49 def main(): 50 in_fc=arcpy.GetParameterAsText(0) 51 in_fld=arcpy.GetParameterAsText(1) 52 c=arcpy.GetParameterAsText(2) 53 if c== "Unique value": 54 uniqueValue=GetFieldUniqueValue(in_fc,in_fld) 55 arcpy.AddMessage("Unique Value:") 56 for i in uniqueValue: 57 arcpy.AddMessage(str(i)) 58 if c=="Duplicate value": 59 duplicateValue= GetDuplicateValue(in_fc,in_fld) 60 arcpy.AddMessage("Duplicate Value,Count:") 61 for key,value in duplicateValue.items(): 62 arcpy.AddMessage("{0},{1}".format(key,value)) 63 if c=="Max/Min/Sum/Average etc.": 64 valueList=GetFieldValueList(in_fc,in_fld) 65 arcpy.AddMessage("Field Name:{}".format(in_fld)) 66 arcpy.AddMessage("Max:{}".format(max(valueList))) 67 arcpy.AddMessage("Min:{}".format(min(valueList))) 68 arcpy.AddMessage("Sum:{}".format(sum(valueList))) 69 arcpy.AddMessage("Average:{}".format(numpy.mean(valueList))) 70 arcpy.AddMessage("Median:{}".format(numpy.median(valueList))) 71 arcpy.AddMessage("Mode:{}".format(GetFieldMode(in_fc,in_fld))) 72 arcpy.AddMessage("Variance:{}".format(numpy.var(valueList))) 73 arcpy.AddMessage("Standard Deviation:{}".format(numpy.std(valueList)))