我的数据框从excel文件中导入了Latitude1 / Longitude1,Latitude2 / Longitude2,并且我正在使用gmaps API生成新列以显示两个位置之间的距离。该代码可以运行,但不提供任何输出。
import pandas as pd
import googlemaps
gmaps = googlemaps.Client(key='MyKey')
source = pd.merge(df['Latitude1'], df['Longitude1'], left_index=True, right_index=True)
destination = pd.merge(df['Latitude2'], df['Longitude2'], left_index=True, right_index=True)
for i in range(len(df['Latitude1'])):
matrix = gmaps.distance_matrix( 'source.iloc[i]', destination.iloc[i]', mode="bicycling")
matrix
{'destination_addresses': [''],'origin_addresses': [''],'rows': {'elements': [{'status': 'NOT_FOUND'}]}],
'status': 'OK'}
df['Distance']
10 Miles
20 Miles
15 Miles
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