I have a large dataset with latitudes and longitudes and i want to map city and state in front of them. Approach which i was using is this:
import pandas as pd import reverse_geocoder as rg import pprint df = pd.read_csv("D:\data.csv") def reverseGeocode(coordinates): result = rg.search(coordinates) # result is a list containing ordered dictionary. pprint.pprint(result) # Driver function if __name__=="__main__": # Coordinates tuple.Can contain more than one pair. for i in range(2): coordinates =(df['latitude'][i],df['longitude'][i]) reverseGeocode(coordinates) Output:
[OrderedDict([('lat', '13.322'), ('lon', '75.774'), ('name', 'Chikmagalur'), ('admin1', 'Karnataka'), ('admin2', 'Chikmagalur'), ('cc', 'IN')])] [OrderedDict([('lat', '18.083'), ('lon', '73.416'), ('name', 'Mahad'), ('admin1', 'Maharashtra'), ('admin2', 'Raigarh'), ('cc', 'IN')])] What i want to do is -
id latitude longitude name admin2 admin1 0 23 13.28637 75.78518 1 29 17.90387 73.43351 2 34 15.72967 74.49182 3 48 20.83830 73.26416 4 54 21.93931 75.13398 5 71 20.92673 75.32402 6 78 19.26049 73.38982 7 108 17.90468 73.43486 8 109 13.28637 75.78518 9 113 15.72934 74.49189 10 126 20.83830 73.26417 11 131 21.93930 75.13399 12 146 20.92672 75.32402 13 152 19.26049 73.38982 14 171 17.90657 73.43382 map name admin1 and admin2 in my dataframe(df) in front of ["latitude","longitude"]

dfis a DataFrame, what little code you shared is unidiomatic."D:\data.csv"? Also, I believe we're missing part of your code, right?