An attributes table has 3 fields: ID, Field1, and Field2 and looks something like this:
ID | Field1 | Field2
1. | text......| 10
2. | text......| NULL
3. | text2....| NULL
4. | text2....| 20
5. | text2....| NULL
In this table there is only 1 value in Field2 for each value of Field1, the rest are all NULL
.
And using python in the field calculator in ArcMap I want to calculate the NULL
values so that the values in Field2 are the same across all equal values of Field1 so the resulting attribute table looks like:
ID | Field1 | Field2
1. | text......| 10
2. | text......| 10
3. | text2....| 20
4. | text2....| 20
5. | text2....| 20
This is what I can come up with but it will not change the NULL
values to what it's reading from the populated row. What I'm trying to have it do is read the populated Field2 value (as x
) for a specific Field1 value then overwrite that and all the other Field2 values that have the same corresponding Field1 value with x
.
Pre-Logic Script:
def Calc( field1 , field2 ):
if field1 == "text" and field2 >= 0:
x = field2
else:
x = None
return x
Field2=
Calc( !Field1! , !Field2! )