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
- Add a new field to the attribute table.
- In the table, click Add Field . The Fields view opens.
- 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'.
- Double-click the Alias column of the new field, and specify an alias for it. In this example, the alias is 'New_ZIP_Codes'.
- Double-click the Data Type column of the new field, and select Text from the drop-down menu.
- On the top ribbon, on the Fields tab, click Save .
- Populate the new field with the values without the leading zeros.
- Open the table, right-click the new field, and click Calculate Field. The Calculate Field window opens.
- In the Calculate Field window, for Input Table, select the table containing the field values without leading zeros.
- For Field Name (Existing or New), select the new field created in Step 1. In this example, the field is 'New_ZIP_Codes'.
- For Expression Type, select Python 3.
- Under Fields, double-click the field with the values without leading zeros. In this example, the field is 'ZIP_CODE'.
- Click Run.
- Add the leading zeros to the values in the new field.
- Open the table, right-click the new field, and click Calculate Field. The Calculate Field window opens.
- In the Calculate Field window, for Input Table, select the table containing the field values without leading zeros.
- For Field Name (Existing or New), select the new field created in Step 1.
- For Expression Type, select Python 3.
- Under Fields, double-click the new field created in Step 1. In this example, the field is 'New_ZIP_Codes'.
- Under Helpers, double-click .zfill().
- 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.
- Click Run.
The image shows the table with the New_ZIP_Codes field displaying 5-digit values.