TypeError:float()参数必须是字符串或数字,而不是'tuple'

问题描述 投票:0回答:1

不会执行。需要找到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)
python jupyter
1个回答
0
投票

我认为“divvy”是一个pandas DataFrame对象。您的代码有两条评论:

  1. 你可能会误解“zip”和“()”,正确的用法是列表(zip(stuff,stuff)),因为这会返回一个列表,保存在“divvy”中。实际上,当前代码以“divvy”而不是值来保存迭代器的副本。
  2. 计算“divvy”中所有条目的距离可能更快,而不是一个一个

例如: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)
© www.soinside.com 2019 - 2024. All rights reserved.