我有一个时间序列数据集,其中给出了接送纬度和经度坐标。 由于城市的坐标几乎没有变化,如何在Python中对它们进行分类?
我想分组以便可以应用分类算法。
我粘贴单行纽约市的接送经度和纬度坐标。
-73.973052978515625 40.793209075927734 -73.972923278808594 40.782520294189453
我已将纬度范围固定为 40.6 到 40.9,经度范围固定为 -73.9 到 -74.25
现在,我想将它们分组,以便可以应用分类算法。
最佳答案
例如,您可以将坐标插入称为坐标
的元组
列表中。请注意,我还附加了一些超出范围的坐标。这是代码:
coordinates = [
(-73.973052978515625,40.793209075927734),
(-73.972923278808594,40.782520294189453),
(-75.9,40.7)
]
filtered = list()
# filtering coordinates
for c in coordinates:
if -74.25 <= c[0] <= -73.9 and 40.6 <= c[1] <= 40.9:
filtered.append(c)
print filtered # here you have your filtered coordinates
输出:
[(-73.97305297851562, 40.793209075927734), (-73.9729232788086, 40.78252029418945)]
关于python - 如何使用纬度和经度坐标进行分组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46179253/