特殊项处理——计算最小距离时如何排除自身

在计算除自身外距离最近的位置时,通过将计算自身时的距离设置为极大值(以能达到目的为准)以规避。这样计算最小距离就会排除自身:

for i in range(2,ws1.get_highest_row()+1):
    distance=[]
    lng1=ws1['B'+str(i)].value
    lat1=ws1['C'+str(i)].value
    #lat1=float(lat1)
    for j in range(2,ws1.get_highest_row()+1):
        if j==i:
            #计算与自身的距离时,将结果设置为一个极大值,
            #这样计算最小距离时就会排除自身
            distance.append(100000000)
            continue

极大值也不能设置过大,否则会有提示:

UserWarning: Discarded range with reserved name
  warnings.warn("Discarded range with reserved name")

原因如下:点击打开链接

It's supposed to be a friendly warning letting you know that some of the defined names are being lost when reading the file. Warnings in Python are not exceptions but informational notices.

Support for defined names is essentially limited to references to cell ranges in openpyxl at the moment. But they can refer to lots of other things like printing settings. However, if the objects/values they refer to are not preserved by openpyxl and the file is saved and later opened by Excel it might complain about the missing objects.


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值