以下代码给出了城市的名称。现在,我想将输出数据放入pandas数据框。
Python Jupyter Notebook 3 +
import geoip2.database
reader = geoip2.database.Reader('F:/GeoLite2-City_20190305/GeoLite2-City.mmdb')
for user in data:
try:
reader.city(user[1]).city.names["en"]
except KeyError:
print(user[1]," No City")
else:
print(user[1]," ",reader.city(user[1]).city.names["en"])
我希望输出为 例如
ip city
12345 Ohio