Referring to the table snippet above, each record has five fields for the last five fiscal years. The data will be either the number of that year or zero.
I need to calculate the Burns_5Yrs field based on the count of the number of non-zero years (in fields FY11 - FY15) in that record. The first three rows have examples manually entered. For example, the first record has activity in FY11 and FY14 so the result for Burns_5Yrs should be 2. The second row is also 2 and the third row is 4.
I've been doing this manually but now I have a table with 198 records so I'd like a programming solution, preferably in Python. Any help would be appreciated as I really don't know where to start.
Dave
Solved! Go to Solution.
The code block can be bypassed completely by using the sum() function directly in the expression block:
sum(1 for field in (!FY11!, !FY12!, !FY13!, !FY14!, !FY15!) if field)
Thanks, this worked perfectly (after I used the actual field names instead of the aliases).
Pandas was too clunky, so numpy in the field calculator... with pictures
The only thing to remember
That's all