-1

I have 2 columns in my dataframe: ip,geoIP

I want to loop through my df and perform a user defined function to geolocate an IP and fill the geoIP column with the return value from the function.

How can i populate the column geoIP with the output from my user defined function which takes the input of the value of the column ip?

1 Answers1

0

You can use apply.

def user_defined_function(x):
  #add your code here


df['geoIP'] = df['ip'].apply(user_defined_function)
Ian Wright
  • 166
  • 4
  • Thank you - your way was so much easier than how i ended up doing it. for i in df3.ip.unique(): ... a = geoLocateIP(i) ... df3.loc[df3.ip==i,'IPGeo'] = a – PhantomOPBro Jan 26 '20 at 18:27