【问题标题】:Pandas latitude longitude binning to 100x100 binsPandas 经纬度分箱到 100x100 分箱
【发布时间】:2021-02-04 10:07:03
【问题描述】:

我有大量的经纬度数据集以及与之相关的其他 KPI,我想要实现的是我想将纬度和经度分箱到 100x100 区域箱组中,然后通过使用 lat 对它们进行分组来聚合其他 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 的 lat long 分箱呢?

谢谢

【问题讨论】:

    标签: python pandas numpy


    【解决方案1】:

    to_bin 是返回一个浮点数,您可以将其格式化为字符串并将经纬度连接在一起:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-08
      • 1970-01-01
      • 2021-03-15
      • 2018-04-06
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 2020-08-03
      相关资源
      最近更新 更多