簡體   English   中英

將屬性表合並到python中

[英]Incorporating attribute table into python

我在ArcMap中使用python進行工作,並有一個問題。 有沒有一種方法可以將屬性表中的數據導入python,如果可以,如何選擇要打印的屬性?

謝謝

可以通過pandas數據框執行一種用python表示屬性表的簡潔方法……尤其是在使用shapefile的情況下。 輸入必須是dbf文件。

# Pandas Option, python 2.7
import arcpy, os, pandas
inTable = r'.dbf'
os.chdir(os.path.dirname(inTable))
outTable = 'table.xls'
arcpy.TableToExcel_conversion(inTable, outTable)
df = pandas.read_excel(outTable)
df.head() # Shows first five records of attribute table

如果要更新字段並直接使用shapefile,也可以使用SearchCursors和UpdateCursors。

# SearchCursor option, python 2.7
import arcpy, os
shapefile = r'.shp'
cursor = arcpy.da.SearchCursor(shapefile, '*')
attributes = []
for row in cursor:
    attributes.append(row)

如果要通過某個字段名查找特定記錄...例如ID 50 ...

for record in attributes:
    if record[0] == 50:
        print record

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM