newell.kate

Calculate Field in python - doesn't calc all records

Discussion created by newell.kate on Mar 1, 2013
Latest reply on Mar 1, 2013 by newell.kate
Wondering if anyone can help me understand why my last three Calculate Field statements do not work...actually it only calcs the same three records in the table, but not the rest.  When I try the same process manually on the table within ArcMap, it works just fine.  All fields are numerical (Double) as you can see from the Add Field statements before the Calculate Field statements.

#RUN STATISTICS ON HOUSING UNITS (EXCLUDES GROUP HOUSING)
arcpy.MakeTableView_management("estpopCityUGA", "HOUSING_UNITS")
arcpy.SelectLayerByAttribute_management("HOUSING_UNITS", "NEW_SELECTION", ' "HOUSE_TYPE" NOT LIKE \'GROUP%\' ')
arcpy.Statistics_analysis("HOUSING_UNITS", "HU_Statistics", [["ESTHU", "SUM"]], ["NHNAME", "HOUSE_TYPE"] )
arcpy.PivotTable_management("HU_Statistics", "NHNAME", "HOUSE_TYPE", "SUM_ESTHU", "HU_STATISTICS_PIVOT")
arcpy.AddField_management("HU_STATISTICS_PIVOT", "SF_UNITS", "DOUBLE", "8", "2", "#", "SF UNITS")
arcpy.AddField_management("HU_STATISTICS_PIVOT", "MF_UNITS", "DOUBLE", "8", "2", "#", "MF UNITS")
arcpy.AddField_management("HU_STATISTICS_PIVOT", "MH_UNITS", "DOUBLE", "8", "2", "#", "SH UNITS")
arcpy.AddField_management("HU_STATISTICS_PIVOT", "TOTAL_UNITS", "DOUBLE", "8", "2", "#", "TOTAL UNITS")
arcpy.AddField_management("HU_STATISTICS_PIVOT", "PCT_SF", "DOUBLE", "9", "6", "#", "PERCENT SF")
arcpy.AddField_management("HU_STATISTICS_PIVOT", "PCT_MF", "DOUBLE", "9", "6", "#", "PERCENT MF")
arcpy.AddField_management("HU_STATISTICS_PIVOT", "PCT_MH", "DOUBLE", "9", "6", "#", "PERCENT MH")

arcpy.CalculateField_management("HU_STATISTICS_PIVOT", "SF_UNITS", "(!SF_ATTACHED! + !SF_DETACHED! + !RESOURCE_LANDS_W__RESIDENCE! + !SF__NO_CODE_ELSEWHERE!) ", "PYTHON", "#")
arcpy.CalculateField_management("HU_STATISTICS_PIVOT", "MF_UNITS", "(!CONDO! + !DUPLEX! + !FOURPLEX! + !MIXED_USE! + !MULTI_FAMILY! + !TRIPLEX! + !WWU!)", "PYTHON", "#")
arcpy.CalculateField_management("HU_STATISTICS_PIVOT", "MH_UNITS", "(!MH_PARK! + !MH_REAL_PROP!)", "PYTHON", "#")
arcpy.CalculateField_management("HU_STATISTICS_PIVOT", "TOTAL_UNITS", "(!SF_UNITS! + !MF_UNITS! + !MH_UNITS!)", "PYTHON", "#")

arcpy.CalculateField_management("HU_STATISTICS_PIVOT", "PCT_SF", "((!SF_UNITS!/!TOTAL_UNITS!)*100)", "PYTHON", "#")
arcpy.CalculateField_management("HU_STATISTICS_PIVOT", "PCT_MF", "((!MF_UNITS!/!TOTAL_UNITS!)*100)", "PYTHON", "#")
arcpy.CalculateField_management("HU_STATISTICS_PIVOT", "PCT_MH", "((!MH_UNITS!/!TOTAL_UNITS!)*100)", "PYTHON", "#")

Outcomes