为了得到一本字典,我已经写了一段代码,它显示了博物馆作为钥匙,地理位置信息作为价值。博物馆总是从博物馆名单(df2)中摘取。我几乎得到了我想要的结果。然而,不幸的是,返回的字典始终保持相同的坐标。因此,这些值不会相应地更新到键中。
我很乐意在这方面寻求帮助!
def geocode(museum):
location = geolocator.geocode(museum, exactly_one = False)
return location
d = {}
for museum in df2:
if geocode(museum) is False:
d[museum] = 'Nothing found'
else:
d[museum] = [location[0].latitude],[location[0].longitude], [len(location)]发布于 2016-12-20 13:04:45
您应该存储geocode函数的返回,然后使用它来分配它,也就是说,位置应该根据对geocode的调用进行更新。
当您构建字典时,请尝试按以下方式修改:
for museum in df2:
loc = geocode(museum)
if loc is None:
d[museum] = 'Nothing found'
else:
d[museum] = [loc[0].latitude],[loc[0].longitude], [len(loc)]https://stackoverflow.com/questions/41243003
复制相似问题