【问题标题】:How to find coordinates from a list of addresses in a dataframe如何从数据框中的地址列表中查找坐标
【发布时间】:2020-07-30 11:14:52
【问题描述】:

我正在尝试在我的数据框中为经度和纬度创建 2 列,我想通过使用名为“详细信息”的地址列来查找它们。

我试过了

geopy.extra.rate_limiter import RateLimiter

locator=Nominatim(user_agent="MyGeocoder")

results['location']=results['Details'].apply

results['point']=results['location'].apply(lambda loc:tuple(loc['point']) if loc else None)
results[['latitude', 'longitude',]]=pd.DataFrame(results['point'].tolist(), index=results.index) 

但这给出了错误“方法对象不可下标”

我想创建一个循环来获取每个地址的所有坐标

Details Sale Price  Post Code   Year Sold
1   53 Eastbury Grove, London, W4 2JT Flat, Lease...    450000.0    W4  2020
2   Flat 148 Wedgwood House Lambeth Walk, London, ...   325000.0    E11 2020
3   63 Russell Road, Wimbledon, London, SW19 1QN ...    800000.0    W19 2020
4   Flat 2 9 Queens Gate Place, London, SW7 5NX F...    400000.0    W7  2020
5   83 Chingford Mount Road, London, E4 8LU Freeh...    182000.0    E4  2020
... ... ... ... ...
47  702 Rutherford Heights Rodney Road, London, SE...   554750.0    E17 2015
48  Flat 48 Highlands Court Highland Road, London,...   340000.0    E19 2015
49  5 Mount Nod Road, London, SW16 2LQ Flat, Leas...    395000.0    W16 2015
50  6 Woodmill Street, London, SE16 3GG Terraced,...    1010000.0   E16 2015
51  402 Rutherford Heights Rodney Road, London, SE...   403200.0    E17 2015
300 rows × 4 columns

【问题讨论】:

  • 详情 售价 邮政编码 售出年份 1 53 Eastbury Grove, London, W4 2JT Flat, Lease... 450000.0 W4 2020 2 Flat 148 Wedgwood House Lambeth Walk, London, ... 325000.0 E11 2020 3 63 Russell Road, Wimbledon, London, SW19 1QN ... 800000.0 W19 2020 4 Flat 2 9 Queens Gate Place, London, SW7 5NX F... 400000.0 W7 2020 5 83 Chingford Mount Road, London, E4 8LU Freeh... 182000.0 E4 2020 ... ... ... ... ... 47 702 Rutherford Heights Rodney Road, London, SE... 554750.0 E17 2015 48 Flat 48 Highlands Court Highland Road, London,... 340000.0 E19 2015 300行 × 4 列
  • 请在问题中发布数据

标签: python pandas geopy


【解决方案1】:

试试这个

import pandas as pd
import geopandas
import geopy
from geopy.geocoders import Nominatim
from geopy.extra.rate_limiter import RateLimiter

locator = Nominatim(user_agent="myGeocoder")
geocode = RateLimiter(locator.geocode, min_delay_seconds=1)

def lat_long(row):
    loc = locator.geocode(row["Details"])
    row["latitude"] = loc.latitude
    row["longitude"] = loc.longitude
    return row

results.apply(lat_long, axis=1)

【讨论】:

  • 我收到以下错误:~/conda/envs/python/lib/python3.6/site-packages/pandas/core/apply.py in series_generator(self) 386 # of it。孩子们:不要在家里这样做。 387 ser = self.obj._ixs(0, axis=0) --> 388 mgr = ser._mgr 389 blk = mgr.blocks[0] 390 AttributeError: 'Series' 对象没有属性 '_mgr'
  • 我已经更新了答案。您可以尝试更新的应答器吗?
  • 同样的错误。我在第一次尝试时也将其更改为 (row['Details'])
猜你喜欢
  • 1970-01-01
  • 2018-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-22
相关资源
最近更新 更多