<?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 Iterating throgh feature classes in gdb resulting in tables in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/iterating-throgh-feature-classes-in-gdb-resulting/m-p/1314007#M68311</link>
    <description>&lt;P&gt;I have been working on a project which includes the creating tables for each feature class in gdp with some info like zeroes, nullsn unknowns. I got successful in making the tables for one class at a time but the plan is iterate through the feature classes, resulting in tables of every feature class&amp;nbsp; formed in one go.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you guys can help me, it would be great help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;My code is as follow:&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import datetime&lt;BR /&gt;import pandas as pd&lt;/P&gt;&lt;P&gt;# Set the workspace to your geodatabase&lt;BR /&gt;geodatabase = r"Z:\Team.gdb"&lt;BR /&gt;arcpy.env.workspace = geodatabase&lt;/P&gt;&lt;P&gt;def analyze(geodatabase):&lt;BR /&gt;dataset = arcpy.ListFeatureClasses(geodatabase)&lt;BR /&gt;result = [&lt;BR /&gt;def analyze(FeatureClasses):&lt;BR /&gt;# Get a list of all fields in the feature class&lt;BR /&gt;fields = arcpy.ListFields(FeatureClasses)&lt;BR /&gt;output = [&lt;BR /&gt;{"Field": f.name, "Type": f.type, "Nulls": 0, "Zeroes": 0, "Unknowns": 0, "DefaultDate": 0}&lt;BR /&gt;for f in fields&lt;BR /&gt;]&lt;BR /&gt;with arcpy.da.SearchCursor(FeatureClasses, [f.name for f in fields]) as cursor:&lt;BR /&gt;for row in cursor:&lt;BR /&gt;for i, val in enumerate(row):&lt;BR /&gt;if val is None:&lt;BR /&gt;result[i]["Nulls"] += 1&lt;BR /&gt;elif val == 0:&lt;BR /&gt;result[i]["Zeroes"] += 1&lt;BR /&gt;elif val == "unknown":&lt;BR /&gt;result[i]["Unknowns"] += 1&lt;BR /&gt;elif result[i]["Type"] == "Date" and val &amp;lt;= datetime.datetime(1929, 12, 31):&lt;BR /&gt;result[i]["DefaultDate"] += 1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;]&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;# Create a pandas DataFrame from the results&lt;BR /&gt;df = pd.DataFrame(result)&lt;BR /&gt;return df&lt;/P&gt;&lt;P&gt;# Display the dateframe as a table in the notebook&lt;BR /&gt;display(analyze(geodatabase)&lt;/P&gt;</description>
    <pubDate>Tue, 01 Aug 2023 12:45:50 GMT</pubDate>
    <dc:creator>ZainAhmad</dc:creator>
    <dc:date>2023-08-01T12:45:50Z</dc:date>
    <item>
      <title>Iterating throgh feature classes in gdb resulting in tables</title>
      <link>https://community.esri.com/t5/python-questions/iterating-throgh-feature-classes-in-gdb-resulting/m-p/1314007#M68311</link>
      <description>&lt;P&gt;I have been working on a project which includes the creating tables for each feature class in gdp with some info like zeroes, nullsn unknowns. I got successful in making the tables for one class at a time but the plan is iterate through the feature classes, resulting in tables of every feature class&amp;nbsp; formed in one go.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you guys can help me, it would be great help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;My code is as follow:&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import datetime&lt;BR /&gt;import pandas as pd&lt;/P&gt;&lt;P&gt;# Set the workspace to your geodatabase&lt;BR /&gt;geodatabase = r"Z:\Team.gdb"&lt;BR /&gt;arcpy.env.workspace = geodatabase&lt;/P&gt;&lt;P&gt;def analyze(geodatabase):&lt;BR /&gt;dataset = arcpy.ListFeatureClasses(geodatabase)&lt;BR /&gt;result = [&lt;BR /&gt;def analyze(FeatureClasses):&lt;BR /&gt;# Get a list of all fields in the feature class&lt;BR /&gt;fields = arcpy.ListFields(FeatureClasses)&lt;BR /&gt;output = [&lt;BR /&gt;{"Field": f.name, "Type": f.type, "Nulls": 0, "Zeroes": 0, "Unknowns": 0, "DefaultDate": 0}&lt;BR /&gt;for f in fields&lt;BR /&gt;]&lt;BR /&gt;with arcpy.da.SearchCursor(FeatureClasses, [f.name for f in fields]) as cursor:&lt;BR /&gt;for row in cursor:&lt;BR /&gt;for i, val in enumerate(row):&lt;BR /&gt;if val is None:&lt;BR /&gt;result[i]["Nulls"] += 1&lt;BR /&gt;elif val == 0:&lt;BR /&gt;result[i]["Zeroes"] += 1&lt;BR /&gt;elif val == "unknown":&lt;BR /&gt;result[i]["Unknowns"] += 1&lt;BR /&gt;elif result[i]["Type"] == "Date" and val &amp;lt;= datetime.datetime(1929, 12, 31):&lt;BR /&gt;result[i]["DefaultDate"] += 1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;]&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;# Create a pandas DataFrame from the results&lt;BR /&gt;df = pd.DataFrame(result)&lt;BR /&gt;return df&lt;/P&gt;&lt;P&gt;# Display the dateframe as a table in the notebook&lt;BR /&gt;display(analyze(geodatabase)&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 12:45:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterating-throgh-feature-classes-in-gdb-resulting/m-p/1314007#M68311</guid>
      <dc:creator>ZainAhmad</dc:creator>
      <dc:date>2023-08-01T12:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating throgh feature classes in gdb resulting in tables</title>
      <link>https://community.esri.com/t5/python-questions/iterating-throgh-feature-classes-in-gdb-resulting/m-p/1314023#M68312</link>
      <description>&lt;P&gt;This is untested, but basically you had some weird structure going on. I think some of it was typos (random open bracket where you define &lt;STRONG&gt;result&amp;nbsp;&lt;/STRONG&gt;as well as random bracket before creating your dataframe).&lt;/P&gt;&lt;P&gt;Basically, you don't need two functions here, especially with the same name. So I combined them into one which takes the GDB as the input and went from there.&amp;nbsp;&lt;/P&gt;&lt;P&gt;List Feature Classes, then loop over each feature class in the list and do your thing (again, didn't test any of this, so you'll have to tweak). They currently all will feed into the same dataframe.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import datetime
import pandas as pd

# Set the workspace to your geodatabase
geodatabase = r"Z:\Team.gdb"
arcpy.env.workspace = geodatabase

def analyze(geodatabase):
    dataset = arcpy.ListFeatureClasses(geodatabase)
    result = {}
    for fc in dataset:
        # Get a list of all fields in the feature class
        fields = arcpy.ListFields(fc)
        output = [{"Field": f.name, 
                    "Type": f.type, 
                    "Nulls": 0, 
                    "Zeroes": 0, 
                    "Unknowns": 0, 
                    "DefaultDate": 0
                    }
                  ]
        with arcpy.da.SearchCursor(FeatureClasses, [f.name for f in fields]) as cursor:
            for row in cursor:
            for i, val in enumerate(row):
                if val is None:
                result[i]["Nulls"] += 1
                elif val == 0:
                result[i]["Zeroes"] += 1
                elif val == "unknown":
                result[i]["Unknowns"] += 1
                elif result[i]["Type"] == "Date" and val &amp;lt;= datetime.datetime(1929, 12, 31):
                result[i]["DefaultDate"] += 1

    # Create a pandas DataFrame from the results
    df = pd.DataFrame(result)
    return df

# Display the dateframe as a table in the notebook
display(analyze(geodatabase)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 13:10:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterating-throgh-feature-classes-in-gdb-resulting/m-p/1314023#M68312</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-08-01T13:10:28Z</dc:date>
    </item>
  </channel>
</rss>

