HOW TO

Add leading zeros to values in a field in an attribute table in ArcGIS Pro

Last Published: February 23, 2021

Summary

In some cases, when adding a standalone table or dataset with an attribute table to ArcGIS Pro, the leading zeros in the fields that contain numbers are not preserved. This article describes the workflow to add leading zeros to numbers in a field. In this example, the ZIP codes field displays 3-digit values instead of 5-digit values. Therefore, two leading zeros must be added to the 3-digit values in a field.

Procedure

  1. Add a new field to the attribute table.
    1. In the table, click Add Field The Add Field icon.. The Fields view opens.
    2. In the Fields view, specify a name for the new field in the Field Name column. In this example, the new field is 'New_ZIP_Codes'.
    3. Double-click the Alias column of the new field, and specify an alias for it. In this example, the alias is 'New_ZIP_Codes'.
    4. Double-click the Data Type column of the new field, and select Text from the drop-down menu.
    5. On the top ribbon, on the Fields tab, click Save The Save icon..
  2. Populate the new field with the values without the leading zeros.
    1. Open the table, right-click the new field, and click Calculate Field. The Calculate Field window opens.
    2. In the Calculate Field window, for Input Table, select the table containing the field values without leading zeros.
    3. For Field Name (Existing or New), select the new field created in Step 1. In this example, the field is 'New_ZIP_Codes'.
    4. For Expression Type, select Python 3.
    5. Under Fields, double-click the field with the values without leading zeros. In this example, the field is 'ZIP_CODE'.
    6. Click Run.
The Calculate Field window with the expression to insert the values from the original field to the new field.
  1. Add the leading zeros to the values in the new field.
    1. Open the table, right-click the new field, and click Calculate Field. The Calculate Field window opens.
    2. In the Calculate Field window, for Input Table, select the table containing the field values without leading zeros.
    3. For Field Name (Existing or New), select the new field created in Step 1.
    4. For Expression Type, select Python 3.
    5. Under Fields, double-click the new field created in Step 1. In this example, the field is 'New_ZIP_Codes'.
    6. Under Helpers, double-click .zfill().
    7. In the expression box of the new field, in the .zfill() function, insert the desired total digits for the new field. In this example, 5 is inserted to add two leading zeros to the 3-digit values.
    8. Click Run.
The Calculate Field window with the selected Expression Type, the .zfill option is selected in the Helpers section and the expression to add the number of leading zeroes.

The image shows the table with the New_ZIP_Codes field displaying 5-digit values.

The attribute table containing the new ZIP codes with leading zeroes.

Article ID: 000025043

Software:
  • ArcGIS Pro 2 7 x
  • ArcGIS Pro 2 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options