Python Forum
ARCPY enter excel table into coded domain
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ARCPY enter excel table into coded domain
#1
This is what i have been trying so far, i cant seem to get the dictionary in the right form.
Appreciate any help i can get

>>> import arcpy
>>> from arcpy import env
>>> env.workspace = 'C:\Milgeo\python'
>>> arcpy.CreateDomain_management('presidentos.gdb', 'amerikanske presidenter', 'amerikas presidenter fra Washington til Trump', "SHORT", "CODED")
<Result 'C:\\Milgeo\\python\\presidentos.gdb'>
>>> import pandas
>>> import pandas as pd
>>> file_path = 'C:\Milgeo\python\president.xlsx'
>>> df = pd.read_excel(file_path, encoding = 'utf-16')
>>> df.to_dict()
{u'Presidenter': {0: u'George Washington', 1: u'John Adams', 2: u'Thomas Jefferson', 3: u'James Madison', 4: u'James Monroe', 5: u'John Quincy Adams', 6: u'Andrew Jackson', 7: u'Martin Van Buren', 8: u'William H. Harrison', 9: u'John Tyler', 10: u'James Knox Polk', 11: u'Zachary Taylor', 12: u'Millard Fillmore', 13: u'Franklin Pierce', 14: u'James Buchanan', 15: u'Abraham Lincoln', 16: u'Andrew Johnson', 17: u'Ulysses S. Grant', 18: u'Rutherford B. Hayes', 19: u'James Garfield', 20: u'Chester A. Arthur', 21: u'Grover Cleveland', 22: u'Benjamin Harrison', 23: u'Grover Cleveland', 24: u'William McKinley', 25: u'Theodore Roosevelt', 26: u'William H. Taft', 27: u'Woodrow Wilson', 28: u'Warren G. Harding', 29: u'Calvin Coolidge', 30: u'Herbert Hoover', 31: u'Franklin D. Roosevelt', 32: u'Harry S. Truman', 33: u'Dwight D. Eisenhower', 34: u'John F. Kennedy', 35: u'Lyndon B. Johnson', 36: u'Richard Nixon', 37: u'Gerald Ford', 38: u'Jimmy Carter', 39: u'Ronald Reagan', 40: u'George H.W. Bush', 41: u'Bill Clinton', 42: u'George W. Bush', 43: u'Barack Obama', 44: u'Donald J. Trump'}}
>>> for code in df.to_dict():
...     arcpy.AddCodedValueToDomain_management('presidentos.gdb', "amerikanske presidenter", 'code', 'df.to_dict[code]')
...
Error:
Runtime error Traceback (most recent call last): File "<string>", line 2, in <module> File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\management.py", line 1492, in AddCodedValueToDomain raise e ExecuteError: ERROR 000378: Invalid Short type. >>>
Reply


Messages In This Thread
ARCPY enter excel table into coded domain - by Just_another_lost_man - Feb-22-2019, 02:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Peaks in time domain frohr 0 495 Jul-06-2023, 02:57 AM
Last Post: frohr
  Python script to summarize excel tables, then output a composite table? i'm a total n surfer349 1 2,413 Feb-05-2021, 04:37 PM
Last Post: nilamo
  I try to import data from Excel table to Word Template. NewbiePyPy 0 3,313 Oct-21-2020, 12:25 PM
Last Post: NewbiePyPy
  Save output into a Excel Sheet with Format Table skaailet 1 2,529 Apr-17-2020, 11:56 PM
Last Post: thirteendec
  Iterating an attribute table using Arcpy teflon 6 4,093 Oct-28-2019, 09:15 PM
Last Post: teflon
  Converting a patterned string or text into excel table soup1987 1 2,158 Oct-03-2019, 01:37 AM
Last Post: Larz60+
  setting environment in arcpy sunny 1 2,834 Feb-25-2019, 06:13 PM
Last Post: sunny
  Avoid hard-coded folderPath in the code (let users provide it) SunOffice024 6 5,408 Sep-08-2018, 06:41 PM
Last Post: SunOffice024
  Converting IP 2 DOMAIN jetli2 8 4,505 May-25-2018, 03:29 PM
Last Post: jetli2
  frequency domain plot jkeertir 0 2,771 Mar-05-2018, 06:54 AM
Last Post: jkeertir

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020