无法将Pandas列中的IP地址转换为latlng(纬度经度)

时间:2018-04-07 04:35:06

标签: python pandas dataframe latitude-longitude geocode

我正在尝试将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)) 

运行这些代码后出现错误

  

属性错误:'系列'对象没有属性' latlng'

我不确定为什么会那样做。有人能在这里给我一些反馈意见吗?真的很感激。

1 个答案:

答案 0 :(得分:3)

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)