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
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.
>>>