Python地理编码将我的城市名称改为奇怪的名称

时间:2018-01-23 04:48:58

标签: python python-2.7 geocode

我尝试在https://pypi.python.org/pypi/geopy的指导下获取几个城市的纬度/经度信息;但是,它对我不起作用。当我输入城市名称列表时,该位置会根据我的城市创建一些有线名称,但对其他人来说是正常的。然后它抱怨UnicodeEncodeError:'ascii'编解码器不能编码位置5中的字符u'\ xed':序数不在范围内(128)。确切的代码如下:

from geopy.geocoders import Nominatim
geolocator = Nominatim()
df=pd.read_csv('testgoo0122.csv') 
print df['google']
list1=df['google'].tolist()
print list1
for i in range(0,len(list1)):
    location = geolocator.geocode("'"+list1[i]+"'")
    print location

#I also tried, which has the exact same problem.
for i in range(0,len(df.google)):
    location=geolocator.geocode("'"+df.google[i]+"'")
    print location

输出看起来像:所以你可以看到我第一次打印城市名称(df ['google'],这是正常的;当我将其转换为列表时,它仍然正常;但是,在地理编码功能之后,位置看起来有线。任何人都可以帮忙吗?非常感谢!

 0    Kerugoya,Kirinyaga,KENYA
 1                   Mie,JAPAN
 2            Hhohho,SWAZILAND
 3                 Granma,CUBA
 4                Holguin,CUBA
 Name: google, dtype: object
 ['Kerugoya,Kirinyaga,KENYA', 'Mie,JAPAN', 'Hhohho,SWAZILAND', 'Granma,CUBA', 'Holguin,CUBA']

Kerugoya, Kirinyaga, Kenya
Japan, Luzerne County, Pennsylvania, 18221, United States of America
Hhohho, eSwatini Swaziland
Granma, Cuba
Traceback (most recent call last):
File "testgoogle2.py", line 30, in <module>
print location

0 个答案:

没有答案