New answers tagged

3

You need to define an intial value for prevX (and for prevY) before you use them in a calculation. Otherwise, the first time the code tries to read their value, it fails. This cannot occur on line 6, because you're not using them as part of a calculation there (just assigning a value to them). Additionally, there is no prevX (or prevY) defined in the ...


0

I was looking to populate the field with sequential numbers and then add leading zeros to all the populated numbers. eg. 04164, 04165, and so on. A co-worker and I found a solution by changing the script to: rec=0 res = 0 ren = 0 def autoIncrement(): global rec global res global ren pStart = 4164 pInterval = 1 if (rec == 0): rec = ...


1

If you want to replace 4164 with 04164, or 4165 with 04165, then just change: return rec with: return "0" + str(rec) or if you need to have 7 places then: return str(rec).zfill(7)


0

There are many ways to "Add" dates. Here's one in CalculateField (place these values into the last 2 boxes of the tool, updating the CreationDateField with your field name). Field to update: add30(!CreationDateField!) Code Block: from dateutil.relativedelta import relativedelta def add30(start): update = start + relativedelta(years=30) return ...


3

You will need to turn on the "Show Codeblock" checkbox in the Field Calculator in order to set some global variables that can be shared across all iterations of the calculation (ie, for all records) and so that you can define a function to perform the calculations which can access these global variables. This allows the field calculator to maintain some ...


5

This approach checks the last 'word' in your string to see if it matches one of the strings you want to eliminate: def FindLabel ([StreetName]): input_string = [StreetName] split_string = input_string.split() if split_string[-1] in ["NB", "SB", "EB", "WB"]: return " ".join(split_string[:-1]) else: return input_string


4

I don't know much about Arcmap syntax for label expressions, but using Python, you could do something like: def FindLabel ([StreetName]): import re input_string = [StreetName] # Regular expression that look for strings ending with a space character # followed by either NB, SB, EB or WB, and replace this part by an empty string return re....


1

I think this should work, def grouped_data_median(t_14, t_15_64, t_65): # total number values n = t_14 + t_15_64 + t_65 # median lower bound mlb = None # groups cumulative frequency before median gcfbm = None # frequency of median group fmg = None # class length of median group clmg = None if t_14 <= t_15_64: ...


Top 50 recent answers are included