我已经使用游标通过python和arcpy创建了一个新的属性表,但是当我尝试打印属性数据(如国家,城市和人口)中的行时,只会打印一个城市。
arcpy.CopyRows_management (folder_path + 'NA_Cities.shp', folder_path + 'Select_Cities.dbf')
fc = folder_path + 'Select_Cities.dbf'
The_cursor = arcpy.da.UpdateCursor(fc, ['CNTRY_NAME', 'Population'])
for row in The_cursor:
if row[0] == 'United States' and row[1] < 8000000:
The_cursor.deleteRow()
elif row [0] == 'Mexico' and row[1] < 8000000:
The_cursor.deleteRow()
elif row[0] == 'Canda' and row[1] < 3000000:
The_cursor.deleteRow()
print row
这是我的结果
Selecting locations
Please Stand By...
Removing the data that does not meet the requirements
[u'Canada', 25000.0]
Finished identifying the cities
提前感谢您的任何建议!
要打印循环中的每一行,print row
语句需要在循环内。
for row in The_cursor:
print row
if row[0] == 'United States' and row[1] < 8000000:
The_cursor.deleteRow()
elif row [0] == 'Mexico' and row[1] < 8000000:
The_cursor.deleteRow()
elif row[0] == 'Canada' and row[1] < 3000000:
The_cursor.deleteRow()
如果只想打印已删除的行,请将该print
语句放在if
/elif
条件中。