Created
February 12, 2020 10:12
-
-
Save jjsantanna/c1083e5d323292dd55dab80bd861bfbf to your computer and use it in GitHub Desktop.
ip2location paid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#by João Ceron | |
import IP2Location | |
def ip2location_geo(pandaseries_ips): | |
ip2location = IP2Location.IP2Location() | |
ip2locationdb="IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ISP.BIN" | |
ip2location.open(ip2locationdb) | |
# country | |
df = pd.DataFrame(columns=['ip','cc']) | |
rows_list = [] | |
unique_ip = pandaseries_ips.unique() | |
for ip in (unique_ip): | |
cc = ip2location.get_country_short(ip).decode("utf-8").replace("'","") | |
lat = ip2location.get_latitude(ip) | |
long = ip2location.get_longitude(ip) | |
row = {"ip": ip, | |
"cc": cc, | |
"lat": lat, | |
"long":long, | |
} | |
rows_list.append(row) | |
df = pd.DataFrame(rows_list) | |
print (len(df)) | |
return (df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment