【发布时间】:2018-03-27 03:27:53
【问题描述】:
我有这个电子表格包含日本的城市名称(不是 100% 正确)、城市坐标、纬度和经度是正确的。我的目标是使用地理编码器数据库中的名称验证我们表中的所有城市名称。
import reverse_geocoder as rg
import pandas as pd
import numpy as np
df=pd.read_excel('desktop/japan.xlsx') #read in the spreadsheet
df['coord']=list(zip(df.lat,df.long)) # zip the lat and lng to make a new series
df.head()
for x,y in df['coord']: # use a for loop to find all the records in reverse_geocoder
coordinates=(x,y)
results=rg.search(coordinates)
print (results)
我从 Jupyter Notebook 得到一些结果,然后出现错误,IndexError: list index out of range。我该如何解决?我用谷歌搜索,没有找到任何有用的解决方案。如何打印所有城市名称?谢谢你一百万。这是电子表格的链接。 Japan city names and coordinates
IndexError Traceback (most recent call=last)
<ipython-input-6-2a5e602f55a8> in <module>()
1 for x,y in df['coord']:
2 coordinates=(x,y)
----> 3 results=rg.search(coordinates)
4 print (results)
~/anaconda3/lib/python3.6/site- packages/reverse_geocoder/__init__.py in search(geo_coords, mode, verbose)
291
292 _rg = RGeocoder(mode=mode, verbose=verbose)
--> 293 return _rg.query(geo_coords)
294
295 if __name__ == '__main__':
~/anaconda3/lib/python3.6/site-packages/reverse_geocoder/__init__.py in query(self, coordinates)
126 else:
127 _, indices = self.tree.pquery(coordinates, k=1)
--> 128 return [self.locations[index] for index in indices]
129
130 def load(self, stream):
~/anaconda3/lib/python3.6/site-packages/reverse_geocoder/__init__.py in <listcomp>(.0)
126 else:
127 _, indices = self.tree.pquery(coordinates, k=1)
--> 128 return [self.locations[index] for index in indices]
129
130 def load(self, stream):
IndexError: list index out of range
【问题讨论】:
标签: python jupyter-notebook geocoding reverse-geocoding