【发布时间】:2018-10-25 09:47:10
【问题描述】:
我试图用 GPS 坐标计算半径 100 米内的地点。我的数据有 4 列,如下所示;
Index Longitude Latitude Count
1 35.897654 26.568987 0
2 32.98717 23.897740 0
3 36.23245 34.243246 0
. .... .... ....
. .... .... ....
我用 Haversine 方法计算了与坐标的距离。我把它描述为一个函数。
haversine([x1,y1],[x2,y2]) 给出 GPS 坐标之间的米。
我的问题出现在下面的代码中;
for x in range(0,25486):
for y in range(1,25486):
a = haversine([cr.iloc[x][0],cr.iloc[x][1]],[cr.iloc[y][0],cr.iloc[y][1]])
if a <= 100 and a > 0:
cr.iloc[x][2]=cr.iloc[x][2]+1
它会引发此错误;
main:5: SettingWithCopyWarning: 试图在 DataFrame 中的切片副本上设置值
请参阅文档中的注意事项:http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
我检查了文档,但找不到有用的东西或者我不明白。
我做错了什么? 执行此嵌套循环操作的正确方法是什么?
提前致谢。
【问题讨论】:
标签: python for-loop nested-loops