I assume df_geo is a single column df, so I believe the following should work:
changes:
return lat, lon
to
return pd.Series([lat, lon])
then you should be able to assign like this:
df_geo_in[['LAT', 'LON']] = df_geo_in.apply(locate)
What you tried to do was assign the result of applymap two new columns, which is incorrect here, since applymap designed to work on each element in df, so if lhs doesn't have the same expected shape, t gives the desired result.
Your last method is also incorrect because you drop duplicate countries, and then expect this to lead each geolocation country back, but the shape is different.
Most likely, for large dfs, a non-duplicated df geolocation will be created, and then combine this back with your large df as follows:
geo_lookup = df_addr.drop_duplicates(['COUNTRY']) geo_lookup[['LAT','LNG']] = geo_lookup['COUNTRY'].apply(locate) df_geo_in.merge(geo_lookup, left_on='COUNTRY', right_on='COUNTRY', how='left')
this will create a df with non-duplicated countries with geodata addresses, and then we will perform a left merge back to master df.
source share