Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Question regarding populating a field in model builder with either Python or VB

$
0
0
I'm looking to populate a field using the calculate tool in model builder. To populate the column within my table I want to use a series of if, then statements so the model accurately assigns the correct value to its respective column. I'm trying to populate the TP_Load_lbs column with the appropriate loading values based on the previously populated values from four separate columns: landuse= Industrial, Commercial and gridcode = 0 or 1, and soil A B C or D, Area. I've been trying to use the code below, but I continue to get an error message. Should I be entering this code in the expression line or the code block.

For example:

if [LU] == "Industrial" and [grid_code] == 1:
[TP_Load_lbs] = 1.8 * [Area]
elif [LU] == "Industrial" and [grid_code] == 0 and [Soil] == "A" or "B":
[TP_Load_lbs] = 0.2 * [Area]
elif [LU] == "Industrial" and [grid_code] == 0 and [Soil] == "C":
[TP_Load_lbs] = 0.4 * [Area]
elif [LU] == "Industrial" and [grid_code] == 0 and [Soil] == "D":
[TP_Load_lbs] = 0.7 * [Area]
elif [LU] == "Commercial" and [grid_code] == 1:
[TP_Load_lbs] = 1.9 * [Area]
elif [LU] == "Commercial" and [grid_code] == 0 and [Soil] == "A" or "B":
[Load_lbs] = 0.3 * [Area]
elif [LU] == "Commercial" and [grid_code] == 0 and [Soil] == "C":
[TP_Load_lbs] = 0.5 * [Area]
elif [LU] == "Commercial" and [grid_code] == 0 and [Soil] == "D":
[TP_Load_lbs] = 0.8 * [Area]

Any help would be gladly appreciated, especially regarding the accuracy of my code to achieve my intended goal.

Thanks,
Natalie

Viewing all articles
Browse latest Browse all 2485

Trending Articles