【问题标题】:make the H3 cell conversion faster in a pandas dataframe使熊猫数据框中的 H3 单元格转换更快
【发布时间】:2021-05-31 15:04:23
【问题描述】:

我有一个表名Rides

start_lat start_long end _lat end_long
29.682413 78.997065 27.682413 76.997065
25.682413 74.997065 24.682413 76.997065

我想将它们转换为 h3 单元格并将它们添加回表格。我正在使用以下代码:

lst1=[]
lst2=[]
for i in range(rides.shape[0]):
    hex1,hex2=0,0
    hex1 = h3.geo_to_h3(rides['start_lat'][i],rides['start_long'][i], 8)
    hex2 = h3.geo_to_h3(rides['end_lat'][i],rides['end_long'][i], 8)
    lst1.append(hex1)
    lst2.append(hex2)
rides['hex_ID1'] = lst1
rides['hex_ID1'] = lst2

这需要很多时间,我在想是否有更快的方法来做到这一点。

【问题讨论】:

    标签: python pandas dataframe loops h3


    【解决方案1】:

    我用了pandas的@​​987654321@函数,可能更合适:

    df.apply(lambda x: h3.geo_to_h3(x.lng, x.lat, resolution=7),axis=1)
    

    【讨论】:

      猜你喜欢
      • 2021-08-16
      • 1970-01-01
      • 2022-01-12
      • 2016-01-28
      • 2019-11-19
      • 2018-01-24
      • 2021-05-27
      • 1970-01-01
      • 2018-07-13
      相关资源
      最近更新 更多