I am trying to apply a function using IP addresses in a DataFrame. The idea is to look at all the IP's in the df['IP'] column and return the country to the df['Country'] column.
import geoip
import pandas as pd
def country_lookup(IP):
return geoip.country(IP)
df = pd.DataFrame({'IP':['99.11.100.60','99.16.198.20','99.88.55.4'],
'Country':['na','na','na']})
Attempted Solution 1
df['Country'] = df['IP'].apply(country_lookup)
Attempted Solution 2
for i in df['IP']:
df['Country'] = country_lookup(i)
Both attempts returned same country code for all rows.
Thanks for the help I am new to programming and have not been able to find a solution.