I created a model that automatically adds a field to a database and concatenates the values in two other fields (block & lot) to create my "pin" field called IDNUM. The problem is that when I download the tax assessment database, I'm losing trailing zeros in both the block and lot fields (ex: 70.10 is 70.1)

Is there a way within the model to analyze the fields before concatenation and add the trailing zeros? I don't have any control over how the tax assessment database is created so I'm looking for a way to streamline this process. Any information would be helpful!

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# IDNUM.py
# Created on: 2017-11-28 11:49:18.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Local variables:
GISDATA = "G:\\ModIV\\GISdata.mdb\\GISDATA"

# Process: Add Field
arcpy.AddField_management(GISDATA, "IDNUM", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field
arcpy.CalculateField_management(GISDATA2, "IDNUM", "[Block] & \"-\" & [Lot]", "VB", "")
  • 1
    Welcome to GIS SE! What is your question? What are you trying to do, what happens when you run your code? Please include any error messages. You can edit your question to include additional information. – Midavalo Nov 28 '17 at 17:01
  • If you can create a new field/define the field type before hand as "text" or "string" it should retain the zeros. – GISKid Nov 29 '17 at 18:34

You can use python ljust() function to left justify text and fill with what ever characters, in your case a zero.

The python expression would be:

str(!Block! ).ljust(5,"0") + "-" + str( !Lot!).ljust(5,"0")

so if block was 70.10 and Lot was 28.10 this would create 70.10-28.10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.