不会执行。需要找到lat和long之间的距离。
divvy['Start Coordinates'] = (zip(divvy['from_station_latitude'], divvy['from_station_longitude']))
divvy['End Coordinates'] = (zip(divvy['to_station_latitude'], divvy['to_station_longitude']))
from geopy.distance import geodesic
dist = []
for i in range(len(divvy)):
dist.append(vincenty(divvy.iloc[i]['Start Coordinates'], divvy.iloc[i]['End Coordinates']).miles)
if (i%1000000==0):
print(i)
我认为“divvy”是一个pandas DataFrame对象。您的代码有两条评论:
例如:1行方法
dist = [vincenty((start_x, start_y), (end_x, end_y)).miles
for start_x, start_y, end_x, end_y in zip(divvy['from_station_latitude'],
divvy['from_station_longitude'],
divvy['to_station_latitude'],
divvy['to_station_longitude'])]
你的方法:
divvy['Start Coordinates'] = list(zip(divvy['from_station_latitude'], divvy['from_station_longitude']))
divvy['End Coordinates'] = list(zip(divvy['to_station_latitude'], divvy['to_station_longitude']))
from geopy.distance import geodesic
dist = []
for i in range(len(divvy)):
dist.append(vincenty(divvy.iloc[i]['Start Coordinates'],divvy.iloc[i]['End Coordinates']).miles)
if (i%1000000==0):
print(i)