# !pip install uszipcode
# Import packages
from uszipcode import SearchEngine
search = SearchEngine(simple_zipcode=True)
from uszipcode import Zipcode
# Define zipcode search function
for index, row in df.iterrows():
result = search.by_coordinates(lat = row[df lat column number], lng = row[df lon column number], returns = 1)
zip = result[0].zipcode
# Add zipcode to the dataframe
df["Zipcode"] = zip
# Save dataframe to csv file (specify path)
df.to_csv("Resouces/df.csv", index=False)
# You can also use itertuples(). It is really faster than iterrows()
# Your for loop may change like the following
for row in df.itertuples(index = False):
# follow remaining code explained above
下面是另一个解决方案(包括注释代码):https://medium.com/@moritz.kittler/ever-struggled-with-reverse-geo-coding-36fe948ad5a3
示例输出:
加载数据集(非必需):
反向地理编码代码:
注意长时间运行(20k行=5-7分钟)。然而,我们在不利用(付费)谷歌API的情况下设法找到了最有效的代码
这是我的代码,我认为它更容易一点:
相关问题 更多 >
编程相关推荐