kamfulebu
kamfulebu

Reputation: 229

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?

Upvotes: 0

Views: 2002

Answers (2)

user1121588
user1121588

Reputation:

If you are working with ArcMap, version 10.1 or greater, check out TableToNumpyArray in the arcpy.da (data access module) There are similar functions to convert to and from tables and feature class datasets. A numpy ndarray (recarray) or a masked arrays is created depending upon whether you have nodata values in your table.. You can also bring in geometry object representation as points if you need to work with geometry

Upvotes: 1

Bot-13
Bot-13

Reputation: 49

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.

Upvotes: 0

Related Questions