使用arcpy 执行此操作的方法是使用光标。
创建一个新表,遍历您的数据,拆分它们并在新表中插入每一行。
这是使用来自 ArcMap(不是 ArcGIS Pro)的arcpy:
import arcpy
import os
src_data = '' # Path to your data
dst_data = '' # New table that will be create.
arcpy.CreateTable_management(os.path.dirname(dst_data),
os.path.basename(dst_data))
# Create the correct fields in the new table
# Assuming the fields have the same name as your data in Row1
# Also assuming the A1, A2, A3 fields .... have the same type/scale/precision/length/etc
# Index split table (index from the Row1 you gave in your example)
dst_idx_split = [[0, 1, 5, 9, 13, 17, 21], # ID A1 B1 C1 D1 Name1 Date
[0, 2, 6, 10, 14, 18, 21], # ID A2 B2 C2 D2 Name2 Date
[0, 3, 7, 11, 15, 19, 21], # etc.
[0, 4, 8, 12, 16, 20, 21]]
src_fields = arcpy.ListFields(src_data)
for idx in dst_idx_split[0]:
field = src_fields[idx]
field_name = field.baseName if field_name in ['ID', 'Data'] else field_name[:-1] # remove the 1/2/3/4 in the field name
arcpy.AddField_management(dst_data, field_name, field.type, field.precision,
field.scale, field.length, field.alias,
field.isNullable, field.required, field.domain)
# Copy the data
i_cur = arcpy.da.InsertCursor(dst_data, '*')
with arcpy.da.SearchCursor(src_data, '*') as s_cur:
for row in s_cur: # for each row of your source data
for idxs in dst_idx_split:
dst_row = [row[idx] for idx in idxs] # extract the data for the new line
i_cur.insertRow(dst_row) # insert it in new table
del i_cur