More

How to copy entire fields into a python list

How to copy entire fields into a python list


I'am trying to find a way to copy entire fields(columns) in a feature class attribute table as lists inside a master list (python).

To illustrate it, consider the table below:

So the list should look something like this:

talukas = [[26190, 26191, 26192, 26193, 26194, 26195,… ], [Tharad, Vadgam, Vav, Amod, Ankleshwar, Bharuch,… ], [None, None, None, None, None, Ahmedabad Ciy,… ] ]

I was trying this,

features = [[row.getValue(f) for f in fields] for row in arcpy.SearchCursor(fc)]

but this gives the entire row values in sub-list and not column value.


Close!

features = [[row.getValue (field.name) for row in arcpy.SearchCursor (fc)] for field in arcpy.ListFields (fc)]

Withda:

features = [[r[0] for r in arcpy.da.SearchCursor (fc, field.name)] for field in arcpy.ListFields (fc)]


fields = [f.name for f in arcpy.ListFields(fc)] theTable=arcpy.da.TableToNumPyArray(fc,fields)