<?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 Exporting Selected Attribute Information to Excel from multiple Feature Classes in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/exporting-selected-attribute-information-to-excel/m-p/1211100#M65520</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a tool that will put all of the selected attribute information from one map ( from 30+ features classes of varying types, ie. polygon, polyline, point) into one, or multiple excel files. In my mind, it would work best if each feature class was it's own tab within a single excel file. So I can look at the file and see what types of features have been selected with in the boundary I am using.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can think how to do this manually, but It would really streamline our process to be able to automate this. Has anyone done anything similar and would be willing to share some code? I'm a beginner python user with just enough knowledge to be dangerous lol.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Fri, 09 Sep 2022 13:24:47 GMT</pubDate>
    <dc:creator>USI_Consultants</dc:creator>
    <dc:date>2022-09-09T13:24:47Z</dc:date>
    <item>
      <title>Exporting Selected Attribute Information to Excel from multiple Feature Classes</title>
      <link>https://community.esri.com/t5/python-questions/exporting-selected-attribute-information-to-excel/m-p/1211100#M65520</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a tool that will put all of the selected attribute information from one map ( from 30+ features classes of varying types, ie. polygon, polyline, point) into one, or multiple excel files. In my mind, it would work best if each feature class was it's own tab within a single excel file. So I can look at the file and see what types of features have been selected with in the boundary I am using.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can think how to do this manually, but It would really streamline our process to be able to automate this. Has anyone done anything similar and would be willing to share some code? I'm a beginner python user with just enough knowledge to be dangerous lol.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2022 13:24:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-selected-attribute-information-to-excel/m-p/1211100#M65520</guid>
      <dc:creator>USI_Consultants</dc:creator>
      <dc:date>2022-09-09T13:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting Selected Attribute Information to Excel from multiple Feature Classes</title>
      <link>https://community.esri.com/t5/python-questions/exporting-selected-attribute-information-to-excel/m-p/1211101#M65521</link>
      <description>&lt;P&gt;My first thought would be to cycle through all the layers and export to pandas data frames, and then go to excel from there.&lt;/P&gt;&lt;P&gt;Have you looked at tutorials like this?&lt;/P&gt;&lt;P&gt;&lt;A href="https://towardsdatascience.com/how-to-build-a-multi-tabbed-excel-file-using-pandas-731391c2cc53" target="_self"&gt;https://towardsdatascience.com/how-to-build-a-multi-tabbed-excel-file-using-pandas-731391c2cc53&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2022 13:35:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-selected-attribute-information-to-excel/m-p/1211101#M65521</guid>
      <dc:creator>Kara_Shindle</dc:creator>
      <dc:date>2022-09-09T13:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting Selected Attribute Information to Excel from multiple Feature Classes</title>
      <link>https://community.esri.com/t5/python-questions/exporting-selected-attribute-information-to-excel/m-p/1211352#M65529</link>
      <description>&lt;P&gt;Using &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/228958"&gt;@Kara_Shindle&lt;/a&gt;'s brilliant idea-&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import pandas as pd
from arcgis.features import GeoAccessor, GeoSeriesAccessor

dataframes = {}

aprx = arcpy.mp.ArcGISProject(r'CURRENT')
for m in aprx.listMaps():
    for lyr in m.listLayers():
        lyrdesc = arcpy.Describe(lyr)
        # Filter to featurelayers and skip rasters
        if lyrdesc.dataType == 'FeatureLayer':
            # check if the layer has a selection
            if lyrdesc.FIDSet:
                # Create df of selected data using the FIDSet
                object_ids = lyrdesc.FIDSet.replace(";", ",") # format to SQL
                # arcpy.AddMessage(object_ids)
                # either use catalogPath or path to get to the feature layer path
                sdf = pd.DataFrame.spatial.from_featureclass(lyrdesc.catalogPath, where_clause=f'OBJECTID IN ({object_ids})')
                # Add to the dataframe dictionary
                dataframes[lyrdesc.name] = sdf

# create the tabbed csv output by iterating over the dataframes dictionary
with pd.ExcelWriter(r'C:\Users\...\Documents\selected_data.xlsx', engine='xlsxwriter') as writer:
    for lyr, df in dataframes.items():
        df.to_excel(writer, sheet_name=f'{lyr}', index=False)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 12:55:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporting-selected-attribute-information-to-excel/m-p/1211352#M65529</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-09-12T12:55:02Z</dc:date>
    </item>
  </channel>
</rss>

