Hello everyone,
I need some help with a python code to populate a field with sequential numbers based on the count of another field in attribute table with field calculator. Like in the image, 10 x hm correspond to 1 km, but when count of hm <10 i need to summarize the last km with the values from hm field.
Any suggestions?
Thank you in advance!
ArcMap 10.8.1
Solved! Go to Solution.
km =
get_km(!hm!)
Code Block
count = len([row for row in arcpy.da.SearchCursor("CApa_hm_km", ["*"])])
last_full_km = int(count / 10)
current_km = 0
def get_km(hm):
global last_full_km
global current_km
current_km += hm / 1000
km = current_km + 1
if current_km < last_full_km:
km = int(km)
return km
km =
get_km(!hm!)
Code Block
count = len([row for row in arcpy.da.SearchCursor("CApa_hm_km", ["*"])])
last_full_km = int(count / 10)
current_km = 0
def get_km(hm):
global last_full_km
global current_km
current_km += hm / 1000
km = current_km + 1
if current_km < last_full_km:
km = int(km)
return km
Thank you very much! it works!