我有一个以下格式的Pandas 数据框:dataframe。

现在我想把所有的起始纬度和起始经度对放到原点,把所有的结束纬度和结束经度对放到目的地。我想得到每一行的距离和持续时间,如下所示。预期输出:
Rental Id | Distance | Duration | Status
0 51649420 0 0 OK
1 51649421 959 214 OK
2
...
15
Run Code Online (Sandbox Code Playgroud)
我尝试遵循两种方法,但它们都给了我超时错误。
方法一:
import googlemaps
from pandas.io.json import json_normalize
gmaps = googlemaps.Client(key='my API key')
for i in range (0,15):
origins = (journeydf['Start Latitude'][i], journeydf['Start Longitude'][i])
destinations = (journeydf['End Latitude'][i], journeydf['End Longitude'][i])
matrix = gmaps.distance_matrix(origins, destinations, mode="bicycling")
matrixdf = json_normalize(matrix,['rows','elements'])
matrixdf['Rental Id']=journeydf['Rental Id']
Run Code Online (Sandbox Code Playgroud)
方法二:
import urllib, json, time
import pandas as pd
def google(lato, lono, …Run Code Online (Sandbox Code Playgroud)