Search code examples
pythonarraysnumpyarcpy

Python - How to add column headers from the generated List


In the code I have generated a list of column headers.

Examples:

fList = [] 
fields = arcpy.ListFields(table)
fList.append(field.name)

print(fList)

#[u'A', u'B', u'C', u'D', u'E']

Separately created numpy array:

matrix = np.array(values_from_list_values)

print(matrix)

[[  2.  45.  32.   9.   2.]
 [  6.  32.   2.  25.   5.]
 [  7.  25.   6.  12.   7.]
 [  8.  12.   5.  32.   8.]
 [  9.  19.   7.  15.   9.]]

Number of columns in the two lists is always equal. Also, the order of columns is always equal.

Is there a possibility that the generated list column headers are added to the matrix? And in what way?


Solution

  • I`m not getting what your requirement exactly, may be you want to add the list in 'fList' as an header to 'matrix', if it is so, you can do it simply as -

    matrix = np.insert(matrix,0,flist,0)
    

    Please accept the answer or elaborate your requirement more.