pandas DataFrame的反向地理编码 [英] Reverse geocoding for pandas DataFrame

查看:85
本文介绍了 pandas DataFrame的反向地理编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有经度和纬度数据,需要将它们转换为纽约的邮政编码。
是否可以处理20,000行的python包?

We have longitude and latitude data and need to transform them into zip codes for new york city. Is there any way to do with a python package for 20,000 rows?

推荐答案

uszipcode包可以完成您的工作

The uszipcode package can do what you're looking for.

from uszipcode import SearchEngine
search = SearchEngine(simple_zipcode=True)
from uszipcode import Zipcode
import numpy as np

def get_zipcode(lat, lon):
    result = search.by_coordinates(lat = lat, lng = lon, returns = 1)
    return result[0].zipcode

lat = np.random.uniform(35,45,10)
lon = np.random.uniform(-100, -110, 10)
df = pd.DataFrame({'lat':lat, 'lon':lon})

df['zipcode'] = df.apply(lambda x: get_zipcode(x.lat,x.lon), axis=1)
df

    lat          lon        zipcode
0   35.535132   -104.418912 88421
1   39.949551   -108.999900 81648
2   39.684619   -104.583286 80018
3   42.080516   -104.489692 82243
4   39.944844   -101.249686 67745
5   38.437412   -101.276961 67861
6   38.900596   -105.557827 80820
7   36.879532   -106.541044 87520
8   43.241656   -107.312935 82630
9   41.541356   -103.589179 69345

这篇关于 pandas DataFrame的反向地理编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆