您的位置:首页 > 其它

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

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

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: