I currently have a column of IP addresses that I'd like to concat with columns for corresponding latitude/longitude.
I'm currently using the following approach but it is super slow:
def getting_ip(row,latlong):
url = r'https://freegeoip.app/json/'+row
headers = {
'accept': "application/json",
'content-type': "application/json"
}
response = requests.request("GET", url, headers=headers)
respond = json.loads(response.text)
if respond[latlong]:
return respond[latlong]
else:
return None
df['Latitude'] = [getting_ip(i,'latitude') if i else None for i in df['IP']]
df['Longitude'] = [getting_ip(i,'longitude') if i else None for i in df['IP']]
Using .apply with the definition doesn't save me much time, either, I spend most of the time in getting the request back. Is there a free, easy way to get latitudes/longitudes from ip addresses (that doesn't expire after a few requests?).