如何使用geopy从坐标获取邮政编码?

问题描述 投票:1回答:1

以下是我一直在使用的代码。我有点新手。由于使用API​​的配额,我一直在测试数据的头部。以下是数据帧的快照:

        latitude    longitude
0   -73.99107       40.730054
1   -74.000193      40.718803
2   -73.983849      40.761728
3   -73.97499915    40.68086214
4   -73.89488591    40.66471445

这是我被绊倒的地方。

train['latlng'] = train.apply(lambda row: '{},{}'.format(row['latitude'], 
row['longitude']), axis=1)
train['geocode_data'] = train['latlng'].map(reverse_geocode)
train['Zip'] =train['latlng'].apply(geolocator.reverse)
train['Zip'].apply(lambda x: pd.Series(x.split(',')))
foo = lambda x: pd.Series([i for i in reversed(x.split(','))])
train['Zip']=train['Zip'].apply(lambda x: str(x))
train['Zip']=train['Zip'].apply(foo)[1]

train

目前,我收到的错误是:

AttributeError: 'Location' object has no attribute 'split'

我如何分割位置,以便我可以拿起邮政编码?

python pandas numpy geolocation geopy
1个回答
1
投票

如果你想要的只是邮政编码,你可以直接访问Location对象中的邮政编码属性。

`location.raw['address']['postcode`]
© www.soinside.com 2019 - 2024. All rights reserved.