<?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: how to change the order of the fields of a table with arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-change-the-order-of-the-fields-of-a-table/m-p/252232#M19395</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan is correct, more on this:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/ideas/1362?sr=search&amp;amp;searchId=fed961b0-5804-4a2e-ac13-09c476c15fde&amp;amp;searchIndex=7"&gt;ArcGIS should allow the ability to permanently reorder fields in a table&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;In arcpy the best way to do this is to create an arcpy FieldMappings object and use it with the Table to Table or Feature Class to Feature Class tool to make a new copy of the table with the order and field names you want. It's a little challenging but it does work. Going the numpy table route is Dan's go-to approach, I am less handy with numpy and pandas than he is. The numpy route is probably faster, but less scalable than using a field mapping inside the arcpy cocoon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note, I should say in &lt;A href="https://community.esri.com/group/1218"&gt;ModelBuilder&lt;/A&gt;‌ you could create a field map using the Calculate Value tool, using an arcpy function to do the work of creating the field map, return the string representation and pass it to the tool that needs it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This seems to be a common use case so I should write a blog post about it sometime.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 31 May 2020 23:45:10 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2020-05-31T23:45:10Z</dc:date>
    <item>
      <title>how to change the order of the fields of a table with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-to-change-the-order-of-the-fields-of-a-table/m-p/252230#M19393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;SPAN lang="en"&gt;&lt;SPAN lang="en"&gt;&lt;SPAN title=""&gt;I am automating a process with model builder.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;SPAN lang="en"&gt;&lt;SPAN title=""&gt;I was looking in the toolbox for a tool that allows me to change the order of my fields.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN lang="en"&gt;&lt;SPAN title=""&gt;But, I did not find anything&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN lang="en"&gt;&lt;SPAN title=""&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN lang="en"&gt;&lt;SPAN title=""&gt;so &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN lang="en"&gt;&lt;SPAN title=""&gt;i'm looking for the option to do it with a script using arcpy.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN lang="en"&gt;&lt;SPAN title=""&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN lang="en"&gt;&lt;SPAN title=""&gt;could you help me with information about how to do it&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 May 2020 22:43:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-change-the-order-of-the-fields-of-a-table/m-p/252230#M19393</guid>
      <dc:creator>RTMRTM</dc:creator>
      <dc:date>2020-05-31T22:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to change the order of the fields of a table with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-to-change-the-order-of-the-fields-of-a-table/m-p/252231#M19394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is none.&amp;nbsp; You might have some success with&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://pro.arcgis.com/en/pro-app/tool-reference/data-management/make-table-view.htm" title="https://pro.arcgis.com/en/pro-app/tool-reference/data-management/make-table-view.htm"&gt;Make Table View—Data Management toolbox | Documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but there is several caveats in the help topic which may make it difficult or impossible&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you ultimately need to make a new featureclass you can use FeatureclassToFeatureclass exporting only the object id field.&amp;nbsp; Then export the table to a numpy array (TableToNumPyArray), sort the fields there then use ExtendTable to join the sorted fields back to the newly created featureclass.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 May 2020 23:37:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-change-the-order-of-the-fields-of-a-table/m-p/252231#M19394</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-05-31T23:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to change the order of the fields of a table with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-to-change-the-order-of-the-fields-of-a-table/m-p/252232#M19395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan is correct, more on this:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/ideas/1362?sr=search&amp;amp;searchId=fed961b0-5804-4a2e-ac13-09c476c15fde&amp;amp;searchIndex=7"&gt;ArcGIS should allow the ability to permanently reorder fields in a table&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;In arcpy the best way to do this is to create an arcpy FieldMappings object and use it with the Table to Table or Feature Class to Feature Class tool to make a new copy of the table with the order and field names you want. It's a little challenging but it does work. Going the numpy table route is Dan's go-to approach, I am less handy with numpy and pandas than he is. The numpy route is probably faster, but less scalable than using a field mapping inside the arcpy cocoon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note, I should say in &lt;A href="https://community.esri.com/group/1218"&gt;ModelBuilder&lt;/A&gt;‌ you could create a field map using the Calculate Value tool, using an arcpy function to do the work of creating the field map, return the string representation and pass it to the tool that needs it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This seems to be a common use case so I should write a blog post about it sometime.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 May 2020 23:45:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-change-the-order-of-the-fields-of-a-table/m-p/252232#M19395</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2020-05-31T23:45:10Z</dc:date>
    </item>
  </channel>
</rss>

