Skip to main content
 首页 » 编程设计

python之如何替换一列属性表中的值

2025年05月04日8lovecherry

我需要替换属性表中一列的值(将名为“label”的列中的零替换为 100)。这可能使用 ogr 或 python 吗?我必须对 500 多个 shapefile 执行此操作。

请您参考如下方法:

在 Esri ArcGIS 领域,Update Cursors通常用于此类操作。

例如

import arcpy 
 
# Your input feature class 
fc = r'C:\path\to\your.gdb\feature_class' 
 
# Start an update cursor and change values from 0 to 100 in a field called "your_field" 
with arcpy.da.UpdateCursor(fc, "your_field") as cursor: 
    for row in cursor: 
        if row[0] == 0: 
            row[0] = 100 
        cursor.updateRow(row)