我有一个包含纬度和经度的大型数据集,我想在它们面前绘制城市和州的地图。我使用的方法是这样的:
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)
输出:
[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')])]
我想做的是——
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
在 ["latitude","longitude"] 前面的我的数据框 (df) 中映射名称 admin1 和 admin2