Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 数据帧反向地理编码_Python_Pandas_Reverse Geocoding_Zipcode - Fatal编程技术网

Python 数据帧反向地理编码

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

我目前有一个数据框,其中包含“纬度”(float)和“经度”(float)列,我想创建一个包含所属邮政编码的列“ZipCode”

到目前为止,我有以下代码:

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)