这里很简单,我正在寻找一个轻量级的库,它允许我查找给定邮政编码的城市/州配对.我正在使用django FWIW.提前致谢.
Mar*_*som 15
试试pyzipcode.主页上的一个例子:
>>> from pyzipcode import ZipCodeDatabase
>>> zcdb = ZipCodeDatabase()
>>> zipcode = zcdb[54115]
>>> zipcode.zip
u'54115'
>>> zipcode.city
u'De Pere'
>>> zipcode.state
u'WI'
>>> zipcode.longitude
-88.078959999999995
>>> zipcode.latitude
44.42042
>>> zipcode.timezone
-6
Run Code Online (Sandbox Code Playgroud)
使用此库uszipcode.
好处:
zipcode和pyzipcode任何其他Python邮编库.>>> from uszipcode import ZipcodeSearchEngine
>>> search = ZipcodeSearchEngine()
>>> zipcode = search.by_zipcode("10001")
>>> print(zipcode)
{
"City": "New York",
"Density": 34035.48387096774,
"HouseOfUnits": 12476,
"LandArea": 0.62,
"Latitude": 40.75368539999999,
"Longitude": -73.9991637,
"NEBoundLatitude": 40.8282129,
"NEBoundLongitude": -73.9321059,
"Population": 21102,
"SWBoundLatitude": 40.743451,
"SWBoungLongitude": -74.00794499999998,
"State": "NY",
"TotalWages": 1031960117.0,
"WaterArea": 0.0,
"Wealthy": 48903.42702113544,
"Zipcode": "10001",
"ZipcodeType": "Standard"
}
# fuzzy city, state search, case insensitive, spelling mistake tolerant
# all zipcode in new york
>>> result = search.by_city_and_state(city="newyork", state="NY")
>>> search.export_to_csv(result, "result.csv")
Run Code Online (Sandbox Code Playgroud)
非常容易构建高级搜索
>>> result = search.find(city="new york",
... wealthy=100000, sort_by="Wealthy", ascending=False, returns=10)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13922 次 |
| 最近记录: |