<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Arcpy replace string in feature class table header in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1159595#M64230</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Update: &lt;/STRONG&gt;I put the fill path in the first parameter of the function and it ran without error. But, I can only get it to produce the desired results from the Notebook, actually. And, of course, I need it to work in a stand-alone. Maybe it's a Python environment issue.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Mar 2022 19:11:43 GMT</pubDate>
    <dc:creator>JaredPilbeam2</dc:creator>
    <dc:date>2022-03-30T19:11:43Z</dc:date>
    <item>
      <title>Arcpy replace string in feature class table header</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1157559#M64148</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I want to be able to remove unwanted values from column headers. When you geocode it adds &lt;EM&gt;User_&lt;/EM&gt; to the beginning of every string. And for the end-user of the table, who's not a tech, this is very convoluted.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JaredPilbeam2_3-1648155135687.png" style="width: 394px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/37288iEEA0F419DE1A8F53/image-dimensions/394x134?v=v2" width="394" height="134" role="button" title="JaredPilbeam2_3-1648155135687.png" alt="JaredPilbeam2_3-1648155135687.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So, what I can do to change the values using Pandas on an excel table I want to be able to do using ArcPy on a feature class. Is this possible? From what I know of cursors you can only change field values. Thanks for any help.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#convert feature class to a table and remove unwanted characters
arcpy.conversion.TableToExcel(out_fc, 'geocode2.xlsx')

#Remove unwanted values from column headers (i.e. USER_) then save as a *.csv
import pandas as pd
df = pd.read_excel(ws + '\geocode2.xlsx')
df.columns = df.columns.str.replace('USER_', '')
df.to_csv(r'')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 21:02:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1157559#M64148</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2022-03-24T21:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy replace string in feature class table header</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1157586#M64149</link>
      <description>&lt;P&gt;Funny - I'm dealing with this exact issue.&lt;/P&gt;&lt;P&gt;If you are using Desktop and ArcPy 2.7 - you're in luck! The MakeFeatureLayer and MakeTableView tools utilize the FieldInfo option to alter field names in the layer, and the new field names will be maintained when exported (FeatureClassToFeatureClass).&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are using Pro and ArcPy 3.x (and it looks like it by your syntax) - my condolences. The functionality has been removed from the MakeFeatureLayer tool. Even though the &lt;A href="https://pro.arcgis.com/en/pro-app/2.8/arcpy/classes/fieldinfo.htm" target="_blank" rel="noopener"&gt;FieldInfo&lt;/A&gt; and &lt;A href="https://pro.arcgis.com/en/pro-app/2.8/tool-reference/data-management/make-table-view.htm" target="_blank" rel="noopener"&gt;MakeTableView&amp;nbsp;&lt;/A&gt;&lt;STRONG&gt;explicitly&lt;/STRONG&gt; show you can change field names, it does not work for me.&lt;/P&gt;&lt;P&gt;I'll be following this thread to see other responses.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 21:44:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1157586#M64149</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-03-24T21:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy replace string in feature class table header</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1157590#M64150</link>
      <description>&lt;P&gt;Yes, cursors only work on the data and not fields. &amp;nbsp;I think you’ll have to create an interim dataset where you can map the User_ fields to the desired output. &amp;nbsp;Or add the fields to the end dataset and use cursors to move the values and then delete the old fields but I think mapping during migration is better.&lt;/P&gt;&lt;P&gt;or &lt;SPAN&gt;use alterfields on them and change the names if possible.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 21:53:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1157590#M64150</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-03-24T21:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy replace string in feature class table header</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1157596#M64152</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;flds = arcpy.ListFields('yourData')&lt;/P&gt;&lt;P&gt;for f in flds:&lt;BR /&gt;&lt;BR /&gt;if f.name.split('_')[0] == 'USER':&lt;BR /&gt;&amp;nbsp; &amp;nbsp; arcpy.AlterField_management("yourData", f.name, f.name.split('_')[1])&lt;BR /&gt;else:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; pass&lt;BR /&gt;print 'fixed aliass'&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 21:52:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1157596#M64152</guid>
      <dc:creator>KevinBell1</dc:creator>
      <dc:date>2022-03-24T21:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy replace string in feature class table header</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1157602#M64154</link>
      <description>&lt;LI-CODE lang="python"&gt;import arcpy
fc0 = r"C:\arcpro_npg\npg\Project_npg\tests.gdb\multi"
flds = ["SHAPE@X", "SHAPE@Y", "Shape_length", "Shape_Area"]
arr = arcpy.da.TableToNumPyArray(fc0, field_names=flds, skip_nulls=True)
nmes = arr.dtype.names
# -- have a look
arr[:1]
array([( 300005.45,  5000005.18,  90.71,  57.50)],
      dtype=[('SHAPE@X', '&amp;lt;f8'), ('SHAPE@Y', '&amp;lt;f8'), ('Shape_length', '&amp;lt;f8'), ('Shape_Area', '&amp;lt;f8')])

nmes  # -- ('SHAPE@X', 'SHAPE@Y', 'Shape_length', 'Shape_Area')

# -- change some of the names
new_nmes = [i.replace("SHAPE@", "") for i in nmes]
arr.dtype.names = new_nmes

arr[:1]
array([( 300005.45,  5000005.18,  90.71,  57.50)],
      dtype=[('X', '&amp;lt;f8'), ('Y', '&amp;lt;f8'), ('Shape_length', '&amp;lt;f8'), ('Shape_Area', '&amp;lt;f8')])

new_nmes  # -- ['X', 'Y', 'Shape_length', 'Shape_Area']

# -- send it back
arcpy.da.NumPyArrayToTable( ... in_array ...,... out_table ...)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 24 Mar 2022 22:16:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1157602#M64154</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-03-24T22:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy replace string in feature class table header</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1159125#M64210</link>
      <description>&lt;P&gt;Thanks for all the suggestions. I've been trying &lt;EM&gt;arcpy.AlterField_management() &lt;/EM&gt;for the most part.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/273218"&gt;@KevinBell1&lt;/a&gt;What you had didn't work verbatim. I think because my data sometimes has more than one underscore. Anytime I attempted to grab the value after the delimiter with s&lt;EM&gt;plit()[1] &lt;/EM&gt;it told me &lt;EM&gt;Iist index out of range&lt;/EM&gt;. So, I started using a combination of &lt;EM&gt;split()&lt;/EM&gt; and &lt;EM&gt;partition()&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;I'm able to print out the values I want, but when I add the line to alter the field I get an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;flds = arcpy.ListFields(r'...pathto\Outputs.gdb\testdelete')#full path to feature class
for f in flds:
    mytuple = f.name.split("_")
    if mytuple[0] == "USER": #if USER before the underscore
        print(f.name.partition("_")[2]) #print what's after the underscore
        arcpy.AlterField_management(flds, f.name, f.name.partition("_")[2])
    else:
        pass
        print('pass me up')&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;pass me up
pass me up
pass me up
pass me up
pass me up
pass me up
pass me up
Reporting_Period
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&amp;lt;ipython-input-133-c6d9bc0ffe7b&amp;gt; in &amp;lt;module&amp;gt;
      4     if mytuple[0] == "USER":
      5         print(f.name.partition("_")[2])
----&amp;gt; 6         arcpy.AlterField_management(flds, f.name, f.name.partition("_")[2])
      7     else:
      8         pass

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in AlterField(in_table, field, new_field_name, new_field_alias, field_type, field_length, field_is_nullable, clear_field_alias)
   5427         return retval
   5428     except Exception as e:
-&amp;gt; 5429         raise e
   5430 
   5431 @gptooldoc('AssignDefaultToField_management', None)

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in AlterField(in_table, field, new_field_name, new_field_alias, field_type, field_length, field_is_nullable, clear_field_alias)
   5424     from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
   5425     try:
-&amp;gt; 5426         retval = convertArcObjectToPythonObject(gp.AlterField_management(*gp_fixargs((in_table, field, new_field_name, new_field_alias, field_type, field_length, field_is_nullable, clear_field_alias), True)))
   5427         return retval
   5428     except Exception as e:

C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in &amp;lt;lambda&amp;gt;(*args)
    510         val = getattr(self._gp, attr)
    511         if callable(val):
--&amp;gt; 512             return lambda *args: val(*gp_fixargs(args, True))
    513         else:
    514             return convertArcObjectToPythonObject(val)

RuntimeError: Object: Error in executing tool&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Fields:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="trable.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/37634iB2E638ACF07CEC76/image-size/large?v=v2&amp;amp;px=999" role="button" title="trable.png" alt="trable.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 21:29:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1159125#M64210</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2022-03-29T21:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy replace string in feature class table header</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1159595#M64230</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Update: &lt;/STRONG&gt;I put the fill path in the first parameter of the function and it ran without error. But, I can only get it to produce the desired results from the Notebook, actually. And, of course, I need it to work in a stand-alone. Maybe it's a Python environment issue.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 19:11:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-replace-string-in-feature-class-table-header/m-p/1159595#M64230</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2022-03-30T19:11:43Z</dc:date>
    </item>
  </channel>
</rss>

