Python 数据帧反向地理编码
我目前有一个数据框,其中包含“纬度”(float)和“经度”(float)列,我想创建一个包含所属邮政编码的列“ZipCode” 到目前为止,我有以下代码:Python 数据帧反向地理编码,python,pandas,reverse-geocoding,zipcode,Python,Pandas,Reverse Geocoding,Zipcode,我目前有一个数据框,其中包含“纬度”(float)和“经度”(float)列,我想创建一个包含所属邮政编码的列“ZipCode” 到目前为止,我有以下代码: location = geolocator.reverse("41.750722, -73.997276") geo_string = location.address.split(",") geo_string[-2] 但是,我不知道如何为数据帧中的每一行运行它。 谢谢你的帮助 不完全确定数据帧的外观,但我相信您应该能够使用.iterr
location = geolocator.reverse("41.750722, -73.997276")
geo_string = location.address.split(",")
geo_string[-2]
但是,我不知道如何为数据帧中的每一行运行它。
谢谢你的帮助 不完全确定数据帧的外观,但我相信您应该能够使用
.iterrows()
:
不完全确定数据帧的外观,但我相信您应该能够使用
.iterrows()
:
我对地质学不熟悉。但假设定义了geolocator,您可以这样做一个单行程序
df = pd.DataFrame([[41.750722, -73.997276]], columns=["Latitude", "Longitude"])
df["ZipCode"] = df.apply(lambda x:geolocator.reverse(str(x["Latitude"])+", "+str(x["Longitude"])).address.split(",")[-2], axis=1)
我对地质学不熟悉。但假设定义了geolocator,您可以这样做一个单行程序
df = pd.DataFrame([[41.750722, -73.997276]], columns=["Latitude", "Longitude"])
df["ZipCode"] = df.apply(lambda x:geolocator.reverse(str(x["Latitude"])+", "+str(x["Longitude"])).address.split(",")[-2], axis=1)