AnsweredAssumed Answered

NumPyArrayToTable error "RuntimeError: create table"

Question asked by dcafdg on Apr 15, 2020
Latest reply on May 12, 2020 by vholubecarcdata-cz-esridist

Hi - I have a web request that returns JSON that I'm trying to get into a file geodatabase table. When I execute arcpy.da.NumPyArrayToTable, I get the following error

RuntimeError: create table

 

This doesn't give me much to go on, so I'm not sure what to try next. Here is my code:

from pathlib import Path
import arcpy
import numpy
import pandas
import requests

proxyDict = {
    "http":"<http_URL>",
    "https":"<https_URL>"
}
url = 'https://api.census.gov/data/2018/acs/acs5?get=NAME,group(B18102)&for=county:*&in=state:53'
fgdb = Path('C:/Temp/ACS2018/ACS2018.gdb')
table = fgdb / 'test_table'

r = requests.get(url)
# r = requests.get(url, proxies=proxyDict) # if you have a proxy server
df = pandas.read_json(r.text)

headers = df[0:1] # first row is headers
header_list = headers.values.tolist()[0] # convert to list
header_list[0] = 'FULL_NAME' # de-duplicate "NAME"
new_columns = dict(zip(list(range(0,len(header_list))), header_list)) #make dict

df2 = df[1:] # data in rows 2+
df3 = df2.rename(columns=new_columns) # add column names back in

# Convert to numpy array, then to table
numpy_array = numpy.array(numpy.rec.fromrecords(df3.values))
names = df3.dtypes.index.tolist()
numpy_array.dtype.names = tuple(names)
arcpy.da.NumPyArrayToTable(numpy_array, str(table))

 

I also tried df3.to_numpy(), but got the same result. 

Outcomes