<?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: List all coded and range values by domain group to table in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/list-all-coded-and-range-values-by-domain-group-to/m-p/1247974#M67842</link>
    <description>&lt;LI-CODE lang="python"&gt;# instead of a DataFrame, define your data as a simple twodimensional list
rows = []
column_names = ["DomainName", "DomainType", "Index", "Code", "Description", "Min", "Max"]

# fill the list
for domain in domains:
    if domain.domainType == "Range":
        row = [domain.name, domain.domainType, 0, None, None, domain.range[0], domain.range[1]]
        rows.append(row)
    else:
        for i, (k, v) in enumerate(domain.codedValues.items()):
            row = [domain.name, domain.domainType, i, k, v, None, None]
            rows.append(row)

# convert to DataFrame
dataframe = pd.DataFrame(rows, columns=column_names)

# export
dataframe.to_csv("N:/folder/domains.csv", index=False)
dataframe.to_excel("N:/folder/domains.xlsx", index=False)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1673606047177.png" style="width: 713px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60372iE7FF96E1D982EE02/image-dimensions/713x252?v=v2" width="713" height="252" role="button" title="JohannesLindner_0-1673606047177.png" alt="JohannesLindner_0-1673606047177.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Jan 2023 10:34:39 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2023-01-13T10:34:39Z</dc:date>
    <item>
      <title>List all coded and range values by domain group to table</title>
      <link>https://community.esri.com/t5/python-questions/list-all-coded-and-range-values-by-domain-group-to/m-p/1247941#M67841</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not a programmer so forgive my ignorance ahead of time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to extract a list of ALL the domains within SDE and group them by name with their corresponding coded or range values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I've done it using Notebook and IDLE.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I don't know exactly how to arrange the results to look like a table. I read about DataFrames and arrays using panda but this is what I got so far:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import numpy as np
import pandas as pd

domains = arcpy.da.ListDomains("E:\ArcProMaps\MySDEConnection.sde")

for domain in domains:
    data1 = ('Domain name: {0}'.format(domain.name))
    s1 = pd.Series(data1)
    print(s1)
    if domain.domainType == 'CodedValue':
        coded_values = domain.codedValues
        for val, desc in coded_values.items():
            data2 = (data1, '{0} : {1}'.format(val, desc))
            s2 = pd.Series(data2)
            print(s2)
    elif domain.domainType == 'Range':
        print(data2,'Min: {0}'.format(domain.range[0]))
        print(data2,'Max: {0}'.format(domain.range[1]))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I get this instead:&lt;/P&gt;&lt;PRE&gt;0    Domain name: piPipeShape
dtype: object
0    Domain name: piPipeShape
1         Circular : Circular
dtype: object
0    Domain name: piPipeShape
1       Horseshoe : Horseshoe
dtype: object
0    Domain name: piPipeShape
1             Oblong : Oblong
dtype: object
0     Domain name: piPipeShape
1    Rectangular : Rectangular
dtype: object
0     Domain name: piPipeShape
1    Trapezoidal : Trapezoidal
dtype: object
0    Domain name: piPipeShape
1     Triangular : Triangular
dtype: object
0    Domain name: piPipeShape
1               Other : Other
dtype: object
0    Domain name: piPipeShape
1           Unknown : Unknown&lt;/PRE&gt;&lt;P&gt;But what I want is something like this and/or easier to read and be able to export to Excel or perhaps a .csv file.&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Domain Name&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;piPipeShape&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;1 (Enumerate them)&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Circular (Code)&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Circular (Description)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;2&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Horseshoe&amp;nbsp;(Code)&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Horseshoe&amp;nbsp;(Description)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;3&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Oblong (Code)&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Oblong&amp;nbsp;(Description)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;4&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Rectangular (Code)&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Rectangular&amp;nbsp;(Description)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;5&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Trapezoidal (Code)&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Trapezoidal&amp;nbsp;(Description)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;6&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Triangular (Code)&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Triangular&amp;nbsp;(Description)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="26px"&gt;Domain Name&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="26px"&gt;SSM_YesNoUnknown&amp;nbsp;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="26px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;1&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Yes&amp;nbsp;(Code)&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Yes&amp;nbsp;&amp;nbsp;(Description)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;No&amp;nbsp;(Code)&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;No&amp;nbsp;(Description)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;3&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Unknown&amp;nbsp;(Code)&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Unknown&amp;nbsp;(Description)&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;etc, etc, etc.....&lt;/P&gt;&lt;P&gt;Also, not sure how to put range codes into a series/array/data frame.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've read more community posts and documentation than I can count.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please lend me a helping hand or at least guide me to the right direction.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 03:59:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-all-coded-and-range-values-by-domain-group-to/m-p/1247941#M67841</guid>
      <dc:creator>Jen_Zumbado-Hannibal</dc:creator>
      <dc:date>2023-01-13T03:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: List all coded and range values by domain group to table</title>
      <link>https://community.esri.com/t5/python-questions/list-all-coded-and-range-values-by-domain-group-to/m-p/1247974#M67842</link>
      <description>&lt;LI-CODE lang="python"&gt;# instead of a DataFrame, define your data as a simple twodimensional list
rows = []
column_names = ["DomainName", "DomainType", "Index", "Code", "Description", "Min", "Max"]

# fill the list
for domain in domains:
    if domain.domainType == "Range":
        row = [domain.name, domain.domainType, 0, None, None, domain.range[0], domain.range[1]]
        rows.append(row)
    else:
        for i, (k, v) in enumerate(domain.codedValues.items()):
            row = [domain.name, domain.domainType, i, k, v, None, None]
            rows.append(row)

# convert to DataFrame
dataframe = pd.DataFrame(rows, columns=column_names)

# export
dataframe.to_csv("N:/folder/domains.csv", index=False)
dataframe.to_excel("N:/folder/domains.xlsx", index=False)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1673606047177.png" style="width: 713px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60372iE7FF96E1D982EE02/image-dimensions/713x252?v=v2" width="713" height="252" role="button" title="JohannesLindner_0-1673606047177.png" alt="JohannesLindner_0-1673606047177.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 10:34:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-all-coded-and-range-values-by-domain-group-to/m-p/1247974#M67842</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-01-13T10:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: List all coded and range values by domain group to table</title>
      <link>https://community.esri.com/t5/python-questions/list-all-coded-and-range-values-by-domain-group-to/m-p/1247978#M67843</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import csv

gdb = r"path\to\geodatabase.sde"

csv_filepath = r"path\to\export.csv"

domains = arcpy.da.ListDomains(gdb)

with open(csv_filepath, 'w', newline="") as csv_file:
    writer = csv.writer(csv_file)
    ## write the header
    writer.writerow(["DOMAIN_NAME", "DOMAIN_TYPE", "CODE/MIN", "DESCRIPTION/MAX"])

    for domain in domains:
        print(domain.name)
        if domain.domainType == 'CodedValue':
            coded_values = domain.codedValues
            for val, desc in coded_values.items():
                print('\t{0} : {1}'.format(val, desc))
                writer.writerow((domain.name,"Coded", val, desc))
        else:
            range_min = domain.range[0]
            range_max = domain.range[1]
            print("\t", range_min, range_max)
            writer.writerow((domain.name,"Range", range_min, range_max))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 10:45:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-all-coded-and-range-values-by-domain-group-to/m-p/1247978#M67843</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2023-01-13T10:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: List all coded and range values by domain group to table</title>
      <link>https://community.esri.com/t5/python-questions/list-all-coded-and-range-values-by-domain-group-to/m-p/1248789#M67844</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417766"&gt;@Clubdebambos&lt;/a&gt;&amp;nbsp; for your help. It worked perfectly!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just have to remember to import csv module too&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2023 17:17:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-all-coded-and-range-values-by-domain-group-to/m-p/1248789#M67844</guid>
      <dc:creator>Jen_Zumbado-Hannibal</dc:creator>
      <dc:date>2023-01-17T17:17:16Z</dc:date>
    </item>
  </channel>
</rss>

