I have a dataframe:df_input1 having 10M rows. One of the column name is "geolocation". For all of the records, I have to find the state name from the geolocation and fill up a column "state" of another dataframe: df_final. For that I have created a function convert_to_state and using this like below:
df_final['State'] = df_input1['geolocations'].apply(convert_to_state)
Is there any faster way to achieve this since this is taking lot of time.
sample data: df_input1
vehicle-no start end geolocations
123 10/12/2019 09:00:12 10/12/2019 11:00:78 fghdrf3245@bafd
456 12/10/2019 06:09:12 10/10/2019 09:23:12 {098ddc76yhfbdb7877]
The custom function:
import reverse_geocoder as rg
import polyline
def convert_to_state(geoloc):
long_lat = polyline.decode(geoloc)[0]
state_name= rg.search(long_lat)[0]["admin1"]
return state_name