我试图返回zipcode作为数据帧中的列。此代码可以工作,但不会在dataframe gps中创建新列。在
import geocoder
import multiprocessing as mp
import pandas as pd
google_key = 'key'
def reverse_gecode(coordinates):
return geocoder.google(coordinates, key = google_key, method = 'reverse').postal
if __name__ == '__main__':
gps = pd.DataFrame({'lat': [27.950575, 40.6936488],
'lon': [-82.4571776, -89.5889864]}) # dataframe mehtod
gps['gps'] = zip(gps.lat, gps.lon)
x = list(gps['gps'])
# multiprocessings
pool = mp.Pool(processes = (mp.cpu_count() - 1))
result_latlong = pool.map(reverse_gecode, x)
pool.close()
pool.join()
我试过了
gps['zip_code'] = gps.apply(lambda x: pool.map(reverse_gecode,
list(x[2])),
axis = 1)
gps['zip_code'] = gps.apply(lambda x: pool.map(reverse_gecode, x[2]),
axis = 1)
gps['zip_code'] = gps.apply(lambda x: pool.map(reverse_gecode, [x[0], x[1]]),
axis = 1)
但是我什么都做不到。我一直得到的错误是
ValueError: ('Unknown location: 27.950575', u'occurred at index 0')
尝试是:
PS我在
geocoder.google()
调用中删除了key=google_key
,因为它对我不起作用输出:
^{pr2}$相关问题 更多 >
编程相关推荐