【发布时间】:2019-07-05 21:27:35
【问题描述】:
当我问我的问题时,请查看随附的快照。 我有一个数据框,其中包含一对从不同程序进行地理编码的纬度/经度,我正在尝试生成(Latitude1/Longitude1)和(Latitude2/Longitude2)之间的距离矩阵等以查找位置之间的距离。
我下面的程序似乎没有读取所有行。
import pandas as pd
import googlemaps
import requests, json
gmaps = googlemaps.Client(key='123)
source = pd.DataFrame({'Latitude': df['Latitude1'] ,'Longitude': df['Longitude1']})
destination = pd.DataFrame({'Latitude': df['Latitude2'] ,'Longitude': df['Longitude2']})
source = source.reset_index(drop=True)
destination = destination.reset_index(drop=True)
for i in range(len(source)):
result = gmaps.distance_matrix(source, destination)
print(result)
预期输出
Distance
12 Miles
10 Miles
5 Miles
1 Mile
数据帧
Key Latitude1 Longitude1 Latitude2 Longitude#2
1 42 -91 40 -92
2 39 -94.35 38 -94
3 37 -120 36 -120
4 28.7 -90 35 -90
5 40 -94 38 -90
6 30 -90 25 -90
【问题讨论】:
标签: python pandas google-maps google-distancematrix-api