shpfexcel

# coding=utf-8
import xlrd
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
data=xlrd.open_workbook('c:/Identity.xlsx')
data.sheet_names()
table=data.sheet_by_name('Identity')
nrows=table.nrows
ncolos=table.ncols
i=1
dic={}
# FID,POINTID,GRID_CODE,ID
#FID_POINT_dict,FID_GRID_dict,FID_ID_dict,ID_FID_dict
FID_GRID_dict={}
FID_ID_dict={}
ID_FID_dict={}
ID_GRID_dict={}
#求得结构POINT_GRID_dict
POINT_GRID_dict={}
#-----------------------
#先赋值
for i in range(1,nrows,1):
    key=int(table.cell(i,3).value)
    if key in ID_GRID_dict.keys():
        print ""
    else:
        ID_GRID_dict[key]=int(table.cell(i, 2).value)
#遍历
# FID,POINTID,GRID_CODE,ID
for i in range(1,nrows,1):
    FID=int(table.cell(i,0).value)
    POINTID=int(table.cell(i,1).value)
    GRID=int(table.cell(i,2).value)
    ID=int(table.cell(i,3).value)
    if int(table.cell(i,2).value)<=ID_GRID_dict[ID]:
        continue
    else:
        del ID_GRID_dict[ID]
        ID_GRID_dict[ID]=GRID

print ID_GRID_dict.__len__()
f=open(r'f:/222.txt','w')
for i in range(1,nrows,1):
    FID=int(table.cell(i,0).value)
    POINTID=int(table.cell(i,1).value)
    GRID=int(table.cell(i,2).value)
    ID=int(table.cell(i,3).value)
    if (ID in ID_GRID_dict.keys())and(GRID==ID_GRID_dict[ID]):
        f.write(str(FID)+"\t"+str(POINTID)+"\t"+str(GRID)+"\t"+str(ID)+"\n")
f.close()


原数据:

FIDPOINTIDGRID_CODEID
121241212573
1212112122183
1212212123133
1212312124133
1211712118243
1211812119183
1211912120233
1212012121412
1210712108243
1210812109183
1210912110183
1211012111233
1211112112183
1211212113302
1211312114302
1211412115292
1211512116302
1211612117302
1210212103193
1210312104193
1210412105133
1210512106291
1210612107302
1209912100193
1210012101193
1210112102133
1209712098243
1209812099243
1209512096374
1209612097384
120891209085
1209012091135
1209112092424
1209212093384
1209312094344
1209412095394
120821208395
1208312084135
1208412085145
1208512086195
1208612087384
1208712088344
1208812089294
120771207885
120781207955
1207912080245
1208012081185
1208112082456
1207112072185
1207212073235
1207312074446
1207412075396
1207512076456
1207612077456
1206512066135
1206612067436
1206712068396
1206812069456
1206912070456
1207012071406
1206212063456
1206312064406
1206412065406
1206012061406
1206112062406
1205712058810
1205812059446
1205912060396
1205312054247
12054120551410
1205512056810
1205612057218
1204712048187
1204812049247
12049120501410
12050120511310
1205112052810
1205212053158
1204012041179
求处理结果:

根据ID号,求取同一ID号的GRID_CODE的最大值所在的POINTID;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值