【问题标题】:vincenty distance in series文森蒂距离系列
【发布时间】:2018-05-28 14:37:45
【问题描述】:

我有带有纬度和经度列的熊猫数据框,并且想要计算两个连续点 pipi+1 之间的 vincenty 距离。

         lat           long  
1    39.9852833333333  116.307367  
2    39.9852166666667  116.309550  
3    39.9851333333333  116.309767  
4    39.9850666666667  116.309883  
5    39.9847333333333  116.309933  

df['distance'] = vincenty( (df['lat'],df['long']), (df['lat'].shift(-1), df['long'].shift(-1)) )  

我收到以下错误:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

【问题讨论】:

    标签: python pandas


    【解决方案1】:

    我认为需要先创建新列,然后使用dropna 删除lat_shiftedlong_shifted 中的最后一个NaNs 行,所以Vincenty_distance 的最后一个值是NaN

    df['lat_shifted'] = df['lat'].shift(-1)
    df['long_shifted'] = df['long'].shift(-1)
    
    df['Vincenty_distance'] = df.dropna().apply(lambda x: vincenty((x['lat'], x['long']), (x['lat_shifted'], x['long_shifted'])), axis = 1)
    

    【讨论】:

      猜你喜欢
      • 2020-10-05
      • 2016-07-23
      • 2016-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-19
      • 1970-01-01
      相关资源
      最近更新 更多