【发布时间】:2021-01-30 15:14:06
【问题描述】:
我已使用 IP2Location 收集有关 IP 地址的信息,并且我希望它在 DataFrame 中,但是当我尝试使用 pd.json_normalize(ip) 时出现错误。
AttributeError: 'IP2LocationRecord' object has no attribute 'values'
我从IP2Location得到的信息就是这种格式,
{'ip': '66.249.79.244', 'country_short': 'US', 'country_long': 'United States of America', 'region': 'California', 'city': 'Mountain View', 'latitude': 37.405991, 'longitude': -122.078514, 'zipcode': '94043', 'timezone': '-08:00'}
我也尝试过使用pd.DataFrame,但是df中的结果是空的,只看到了列名。
df = pd.DataFrame(ip, columns = ['ip','country_short','country_long','region','city','latitude','longitude','zipcode','timezone'])
预期结果
ip country_short country_long .... zipcode timezone
0 66.249.69.244 US United States of America 94043 -08:00
【问题讨论】:
标签: python pandas dataframe ip2location