HOW TO

Remove spaces from values of a string field in an attribute table in ArcGIS Pro

Last Published: April 15, 2024

Summary

In ArcGIS Pro, it is sometimes necessary to remove extra spaces from the values of a string field in an attribute table. This can be achieved using the strip() Python function, which removes any characters, including spaces. This article describes the workflow to remove spaces using the strip() Python function in the Calculate Field tool.

In this example, the extra spaces from the values of the COUNTY field are removed to uniformize the format.

The COUNTY field in the attribute table.
Note:
• The strip() function removes all leading and trailing characters mentioned in the argument. If no argument is presented, only spaces are removed.
• To remove either leading or trailing spaces, use the lstrip() or rstrip() functions respectively.
• This function only works on string and text fields, not integer fields.

Procedure

  1. Open the ArcGIS Pro project.
  2. In the Contents pane, right-click the layer and click Attribute Table to open the layer's attribute table.
The Contents pane with the Attribute Table option displayed.
  1. In the attribute table, right-click the field name containing the values with spaces to be removed, and click Calculate Field. The COUNTY field is used in this example.
The COUNTY field with the Calculate Field option displayed.
  1. Configure the parameters in the Calculate Field window.
  1. For Input Table, ensure the layer selected in Step 2 is prefilled. In this example, the input table is Petroleum_Well.
  2. For Field Name, ensure the field selected in Step 3 is prefilled. Otherwise, select the field from the drop-down menu. In this example, the field name is COUNTY.
  3. For Expression Type, select Python 3.
  4. For Expression, in the expression box, type the code provided below. Replace 'Field Name' with the name of the field selected in Step 3.
!Field Name!.strip()
Note:
The Calculate Field tool changes the input data permanently. To enable undo, toggle the Enable Undo option on in the Calculate Field window before running the tool. Or, create a new field and configure the field.
The Calculate Field window
  1. Click OK.

The spaces are removed from the values in the COUNTY field.

The COUNTY field in the attribute table.

Article ID: 000028712

Software:
  • ArcGIS Pro 3 1
  • ArcGIS Pro 3 0
  • ArcGIS Pro 3 2

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