New answers tagged

1

For a beginner, there are three important concepts to accomplish this: How to use the codeblock part of the Field Calculator to write and call a function How to test for null values How to return the first or last four characters of a string I will explain each of these concepts below. Item 1: You need to check "Python" and "Show Codeblock", then ...


4

Using Python in the field calculator, you could try the following expression: 1 if !myField! > 0.0 else 0 Or if you want it based on the polygon area, try: 1 if !shape.area! > 0.0 else 0 Since booleans are automatically cast to integers (1 or 0), you can do the same thing more simply as: !myField! > 0 or !shape.area! > 0 If there is a ...


2

What the !field1! if !field1! else '' expression does is evaluate if the corresponding value of !field1! exists or not. If there is a value, then it keeps that value and adds it to 'Comment'. However, if there is no value (it evaluates to None) it will keep and empty string (''). Here is an illustrative example: Suppose the value of field1 is 'ABC001' for ...


2

With python parser try: Code block: def updateValue(field1, field2): if field1 is None: return field2 else: return '0' Call with: realfieldname1= updateValue(!realfieldname1!,!realfieldname2!) When you call the function you must use the real fieldname enclosed in !!


4

All geoprocessing tools honour selections. So simply select the rows where column 1 has the NULL values then run a field calculate and select the field you want the values to come from. As you have a selection only those rows will be updated. Absolutely no code required.


1

I finally figured out the problem. Was my index position. So this type of code works as well. permit_fix = replace(!permit_num!) Code Block import re def replace(val): if (val[0:2] == "07"): return re.sub ('07','39', val) elif (val[0:2] == "10"): return re.sub ('10','39', val) elif (val[0:2] == "11"): return re....


1

You can use a list comprehension to index and replace the first characters for each item in a list. For example: test = ["3901","1420","2270","3985"] def replace(val): new = ["39" + i[2:] if i[:2] != "39" else i for i in test] print (new) replace(test)


0

I was able to use a few examples elsewhere, and came up with this working solution. All I want to do now is bold and underline the UNITID. I'm posting the code here for anyone else who wants an easy solution. def FindLabel ( [UNITID], [QTY1], [SIZE1], [QTY2], [SIZE2], [QTY3], [SIZE3], [QTY4], [SIZE4] ): if [UNITID] and [QTY1] and [SIZE1] and [...


0

Thank you @smiller: I implemented all your suggestions. I had to change the order of the lines so that it formatted before calling the function but the below now works. from datetime import datetime, date, time, timedelta def updateSecond(Da): then = datetime.strptime(Da, '%m/%d/%Y %I:%M:%S %p') sec = timedelta(seconds=30) updateSecond = then + ...


3

Despite being a date field, the "Da" field would be treated as unicode within the Field Calculator. You may need to first convert the field value to datetime format, as described here: https://stackoverflow.com/questions/22219210/convert-the-unicode-to-datetime-format?rq=1 While you have defined a function, you are not calling it, and the function itself has ...


1

You probably have null values in one or more fields (not to be confused with a the literal string value of "Null") which are getting passed through as None, a special Python type which can't be concatenated to strings in that way. You're only currently checking for empty strings, but a more generic way to check for either would be to do simply if [field], ...


Top 50 recent answers are included