How can I view the attribute table of a shapefile or a raster file as a database using ArcPy?

closed as off-topic by PolyGeo Jun 7 at 21:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.


It depends on what you mean by "view" and "as a database".

To simply extract the data from a table into a data structure in Python using Arcpy, use arcpy.da.SearchCursor().

See: https://pro.arcgis.com/en/pro-app/arcpy/data-access/searchcursor-class.htm

If this answer is too vague, that's probably because you're question is a little on the vague side, and it's difficult to know what it is you really want.


fields = [f.name for f in arcpy.ListFields(fc)]
with arcpy.da.SearchCursor(fc, fields) as cur:
    for row in cur:
        print "{}, {}, {}".format(row[0], row[1], row[2])
  • I want to view the database as we do in pandas – lsr729 Jun 7 at 6:27
  • 3
    In that case, you may want to google something like: arcpy feature class to pandas dataframe . This would reveal many useful answers, including: developers.arcgis.com/python/guide/… – Son of a Beach Jun 7 at 6:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.