我已经使用 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