【问题标题】:Unable to convert IP address in Pandas column to latlng (Latitude Longitude)无法将 Pandas 列中的 IP 地址转换为 latlng(纬度经度)
【发布时间】:2023-03-20 15:01:01
【问题描述】:

我正在尝试将 Pandas 列(每行包含 IP 地址)中的数据转换为纬度和经度。以下是我的代码:

import geocoder

d = pd.DataFrame({'ip_address' : ['49.206.217.180', '200.8.245.246', '186.188.35.217']})

d['coordinate'] = d.apply(geocoder.ip(d['ip_address'].latlng)) 

运行这些代码后出现错误

AttributeError: 'Series' 对象没有属性 'latlng'

我不知道为什么会这样。有人可以在这里给我一些反馈吗?真的很感激。

【问题讨论】:

    标签: python pandas dataframe latitude-longitude geocode


    【解决方案1】:
    import geocoder
    
    d = pd.DataFrame({'ip_address' : ['49.206.217.180', '200.8.245.246', '186.188.35.217']})
    d['coordinate'] = d['ip_address'].apply(lambda x: geocoder.ip(x).latlng) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-15
      • 2010-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多