我有大量的纬度和经度数据集以及与其相关的其他 KPI,我想要实现的目标是将纬度和经度分箱到 100x100 区域箱组,然后通过使用纬度对它们进行分组来聚合其他 KPI长斌.我以前尝试过这个方法
step = 0.001
to_bin = lambda x: np.floor(x / step) * step
data["latbin"] = data['client_latitude'].map(to_bin)
data["lonbin"] = data['client_longitude'].map(to_bin)
但它没有按预期工作 那么如何实现经纬度的 100x100 分箱?
谢谢
最佳答案
to_bin
返回一个 float ,您可以将其格式化为字符串并将纬度和经度连接在一起:
to_bin = lambda x: '%0.3f' % (np.floor(x / step) * step)
data["bin"] = data['client_latitude'].map(to_bin) + 'x' + \
data['client_longitude'].map(to_bin)
关于python - Pandas 纬度经度分箱至 100x100 分箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66043410/