问题描述
我有这个CSV文件,我用这个python脚本喂食。
import csv
从geopy。 geocoders import OpenCage
geolocator = OpenCage()#其中需要一些参数
with open('/ Users / Ian / Desktop / Test02 / 151213_2015_martyrs_year_filtered_areas.csv','rb')as csvinput :
with open('151213_locations_filtered_opencage.csv','w')as csvoutput:
output_fieldnames = ['Province','Area','Country','Latitude','Longitude']
writer = csv.DictWriter(csvoutput,delimiter =',',fieldnames = output_fieldnames)
reader = csv.DictReader(csvinput)
读取器中的行:
使用您的csv列名称替换dict项目
query =','。(row ['Country'],row ['Province'],row ['Area'] )
print(query)
try:
address,(latitude,longitude)= geolocator.geocode(query)
except:
latitude ='N / A'
longitude ='N / A'
这里是写区段
output_row = {}
output_row ['Province' ] = row ['Province']
output_row ['Area'] = row ['Area']
output_row ['Country'] = row ['Country']
output_row ['Latitude '] = latitude
output_row ['Longitude'] =经度
writer.writerow(output_row)
CSV FILE节选
省,地区,国家
Aleppo,Jarablus,叙利亚
阿勒颇,叙利亚
阿勒颇,叙利亚Kafrnaya
阿勒颇,Bazzaa,叙利亚
阿勒颇,阿南达,叙利亚
阿勒颇,萨勒,叙利亚
Aleppo,Kafrahamreh,叙利亚
阿勒颇,叙利亚Batbo
阿勒颇,叙利亚胡鲁克
阿勒颇,苏卡里邻里,叙利亚
阿勒颇,Ein ArabKobani:Srain,叙利亚
阿勒颇,巴布亚,叙利亚
阿勒颇,叙利亚Tel Rifaat
阿勒颇,伊扎兹,叙利亚
阿勒颇,Sfaireh,叙利亚
阿勒颇,Hritan,叙利亚
Aleppo,Manbej,叙利亚
阿勒颇,Karm Bitar,叙利亚
阿勒颇,阿塔里卜,叙利亚
阿勒颇,尼拉布,叙利亚
阿勒颇,Afrin:Mariameen,叙利亚
阿勒颇,Zerbeih镇,叙利亚
阿勒颇,叙利亚,Sakhour
阿勒颇,塔尔阿巴德,叙利亚
阿勒颇,塔尔阿兰,叙利亚
阿勒颇,Talqrah,叙利亚
Aleppo,Tqad,叙利亚
阿勒颇,叙利亚达拉特Azza
阿勒颇,巴亚努恩,叙利亚
阿勒颇,Misakan,叙利亚
阿勒颇,Qosaileh,叙利亚
阿勒颇,Mashatieh邻里,叙利亚
Aleppo, Kabbasin,叙利亚
阿勒颇,Harjalleih,叙利亚
阿勒颇,Bab路邻里,叙利亚
阿勒颇,Qanater村,叙利亚
阿勒颇,Maskaneh,叙利亚
阿勒颇,Jeb el -qibba,叙利亚
阿勒颇,Hwer al-Aes,叙利亚
阿勒颇,Ein阿拉伯Kobani,叙利亚
Aleppo,Anjareh,叙利亚
Aleppo,Hayyan,叙利亚
阿勒颇,谢赫赛义德,叙利亚
阿勒颇,利拉蒙,叙利亚
阿勒颇,卡拉姆Muayassar,叙利亚
阿勒颇,Tel Daman:Tel Maseh村,叙利亚
Aleppo, Eibeen Simon,叙利亚
阿勒颇,Deir Hafir,叙利亚
阿勒颇,谢赫阿里村,叙利亚
阿勒颇,Afrin,叙利亚
阿勒颇,Khan Toman,叙利亚
Aleppo,叙利亚Rasm al-Aboud村
阿勒颇,Hulluk:Ein el-Tal,叙利亚
阿勒颇,Khan el-Asal,叙利亚
Aleppo,Alshyoukh Alfoqani,叙利亚
Aleppo, ,叙利亚
阿勒颇,叙利亚叙利亚
阿勒颇,Mkahleh,叙利亚
阿勒颇,Zebdieh,叙利亚
阿勒颇,安萨里,叙利亚
阿勒颇,Bustan el Qassr,叙利亚
阿勒颇,东安萨里,叙利亚
阿勒颇,班杰拉,叙利亚
阿勒颇,Kallaseh,叙利亚
阿勒颇,塔勒备忘录,叙利亚
阿勒颇,Museijrat al-Bosheikh,叙利亚
阿勒颇,阿齐兹亚,叙利亚
阿勒颇,萨拉赫丁,叙利亚
阿勒颇,Tel Rifaat:Herpel,叙利亚
阿勒颇,Shokaileh,叙利亚
Aleppo,Kafrobeid,叙利亚
阿勒颇,Jazraya,叙利亚
阿勒颇,Fardous,叙利亚
阿勒颇,Mestaha,叙利亚
阿勒颇,Bab Neirab,叙利亚
阿勒颇,马吉耶,叙利亚
Aleppo ,Karam el-Nuzha,叙利亚
Aleppo,Tal Hdia,叙利亚
Aleppo,Talhia,叙利亚
Aleppo,Karam Al-Tarrab,叙利亚
Aleppo,Zerbeih镇,叙利亚
Aleppo,叙利亚,Tel Daman
Aleppo,叙利亚大奥尔良
Aleppo,叙利亚,Ritian
Aleppo,Barkoum,叙利亚
Aleppo,Sheikh Maksoud,叙利亚
阿勒颇,Ihres,叙利亚
阿勒颇,Sfaireh:阿赞山,叙利亚
阿勒颇,Hader村,叙利亚
阿勒颇,Mraij,叙利亚
阿勒颇,Deir Hafir:电话Ayoub,叙利亚
阿勒颇,叙利亚Abtin村
阿勒颇,叙利亚Kafrnoran
阿勒颇,Deir Hafir:叙利亚谢赫·艾哈迈德村
阿勒颇,叙利亚Rasm al-Sheikh
Aleppo, Ezaa邻里,叙利亚
Aleppo,Zitan,叙利亚
阿勒颇,Kfarkarmin村,叙利亚
Aleppo,Blas,叙利亚
Aleppo,Seif El-Dawla,叙利亚
Aleppo, Bab el-Faraj,叙利亚
阿勒颇,Teljabin,叙利亚
阿勒颇,Rjaileh,叙利亚
阿勒颇,Kafra,叙利亚
Aleppo,Ziyareh,叙利亚
Aleppo,Sfaireh:沙特阿拉伯叙利亚
阿勒颇,塔拉恩,叙利亚
阿勒颇,萨哈勒,叙利亚
阿勒颇,沙尔,叙利亚
阿勒颇,叙利亚
阿勒颇,Mowasalat,叙利亚
Aleppo,Qadi Askar,叙利亚
Aleppo,Mashad,叙利亚
Aleppo,Izaz:Kfarkplpin,叙利亚
Aleppo,Rashideen,叙利亚
Aleppo,Marja,叙利亚
Aleppo,Kafin,叙利亚
阿勒颇,叙利亚达比克
阿勒颇,叙利亚苏莱曼al-Halabi
阿勒颇,叙利亚梅耶尔
阿勒颇,叙利亚Tlaleen
阿勒颇,哈马达尼亚,叙利亚
阿勒颇,电话卡塔,叙利亚
阿勒颇,Tel Shgaib,叙利亚
阿勒颇,塔迪夫,叙利亚
阿勒颇,曼比:代尔贾马尔,叙利亚
阿勒颇,叙利亚Qubtan el-Jabal
阿勒颇,阿赫蒂姆拉特,叙利亚
阿勒颇,Majas村,叙利亚
阿勒颇,Masaken al-Sabeel,叙利亚
Aleppo,Sheikh Khader,叙利亚
Aleppo,Masharq,叙利亚
阿勒颇,叙利亚Bshentreh村
阿勒颇,叙利亚胡尔村
阿勒颇,阿拉伯叙利亚:苏里亚
Aleppo,Amerieh,叙利亚
阿勒颇,萨菲拉:塔拉兰,叙利亚
阿勒颇,吉安娜,叙利亚
阿勒颇,阿什拉菲,叙利亚
阿勒颇,Qustal哈拉米,叙利亚
阿勒颇,Marestit el-汗,叙利亚
阿勒颇,哈米迪亚村,叙利亚
阿勒颇,Muyassar邻里,叙利亚
阿勒颇,Zyade村,叙利亚
阿勒颇,Bab:Braij宫村,叙利亚
Aleppo, al-Hosh村,叙利亚
阿勒颇,Darat Azza:西蒙山:Deir Simeon村,叙利亚
阿勒颇,阿兰,叙利亚
阿勒颇,Shwehneh山,叙利亚
Aleppo,Masakin Hanano ,叙利亚
阿勒颇,Kafrdaal,叙利亚
阿勒颇,叙利亚,Hoteh
阿勒颇,Rabiea,叙利亚
阿勒颇,叙利亚
阿勒颇,卡拉姆el-叙利亚
阿勒颇,马达因卡比拉,叙利亚
阿勒颇,马伊迪邻里,叙利亚
阿勒颇,Jamiat al-Zahraa,叙利亚
阿勒颇,马拉特Artik,叙利亚
Aleppo, Al-Afandi,叙利亚
阿勒颇,新阿勒颇,叙利亚
阿勒颇,迪尔哈菲尔:Rasm Harmel,叙利亚
阿勒颇,Ein阿拉伯Kobani,叙利亚
阿勒颇,Absmo,叙利亚
阿勒颇,迪尔哈桑,叙利亚
阿勒颇,叙利亚,叙利亚
阿勒颇,西蒙山:曼苏拉,叙利亚
阿勒颇,阿塔里布:阿勒颇,Kafarnaha,叙利亚
阿勒颇,Bab Qinnasrin,叙利亚
阿勒颇,佩德罗山,叙利亚
阿勒颇,Dahrat阿瓦德,叙利亚
阿勒颇,Qirliq邻里,叙利亚
阿勒颇,Um Hosh,叙利亚
阿勒颇,Baideen,叙利亚
阿勒颇,Akhtareen,叙利亚
阿勒颇,伊扎兹:索兰镇,叙利亚
阿勒颇,哈莱赫,叙利亚
Aleppo, Bab:叙利亚Abu Taltal村
阿勒颇,Bareh Azzawi,叙利亚
阿勒颇,马尔哈,叙利亚
阿勒颇,Ezaa邻里,叙利亚
Aleppo,Kafernasaeh,叙利亚
Aleppo ,Karam el-Jabal,叙利亚
Aleppo,Tadeel,叙利亚
Aleppo,Abo Mjaher,叙利亚
Aleppo,al-Aes,叙利亚
Aleppo,khalsa,叙利亚
阿勒颇,叙利亚
阿勒颇,阿拉斯,叙利亚
阿勒颇,哈尔萨,叙利亚
阿勒颇,Jisr el-Hajj,叙利亚
阿勒颇,Qataneh,叙利亚
Aleppo, Ahmadia,叙利亚
Aleppo,Garliq,叙利亚
Aleppo,Sheikh Najjar,叙利亚
但原来的csv看起来像这样
rowid,Name,Status,Sex,Province,Area,Date_of_Death,Cause_of_Death
1,Hasan Ali Saad al-Hareeri,平民,成人 - 男性,Daraa,Sawara,2015-12-10,战机轰击
2,Riham Adnan Swais,平民,成年女性,Homs,Telbeiseh, 12-10,炮轰
3,Ammar Ahmad al-Njoam,平民,成人 - 男性,Aleppo,Jarablus,2015-12-10,爆炸
4,Yaseen Slaiman al-Salkhadi,男,Daraa,Jassim,2015-12-10,战机炮击
5,Ayman Noman Qanatra,平民,成人 - 男,Daraa,Jassim,2015-12-10,战机炮击
6,Abdul Kareem Mohammad al-Tamki,平民,成人 - 男性,Daraa,Sheikh Miskeen,2015-12-10,战机轰炸
7,Ahmad Mohammad al-Tamki,平民,儿童 - 男,Daraa,Sheikh Miskeen,2015-12 -10,战机轰击
8,Hamze Mohammad al-Tamki,平民,成人 - 男,Daraa,Sheikh Miskeen,2015-12-10,Warplane炮轰
9,Mohammad Ahmad al-Khaleel,平民,成人 - 男性,Daraa,Sheikh Miskeen,2015-12-10,炮轰
10,Abdul Kareem Abdul Lateef al-Mohammad,非民事,成人 - 男性,Hama,Lattamna,拍摄
11,Mahdi Basem Qatteni,非平民,成人 - 男性,Idlib,Khan Sheikhoun,2015-12-10,拍摄
12,Ahmad Ibraheem al-Sayed Omar,阿勒颇,2015-12-10,战机轰击
13,身份不明,平民,儿童 - 男,阿勒颇,Kafrnaya,2015-12-10,战机炮击
14,身份不明1,女,阿勒颇,Bazzaa,2015-12-10,战机轰击
15,身份不明2,平民,儿童 - 男,阿勒颇,Bazzaa,2015-12-10,战机轰击
16,平民,儿童 - 男,阿勒颇,Bazzaa,2015-12-10,战机轰炸
17,Mohammad Ahmad al-Farhoud,平民,成人 - 男,Idlib,Telminis,2015-12-10,射击
18,Yousef al-Saleh,非民事,成人 - 男性,Idlib,Kafroumeh,2015-12-10,射击
19,巴塞尔Hsain al-Knoah,非平民,成年 - 男性,Idlib,Kafroumeh ,2015-12-10,射击
20,巴塞尔Abdul Rahman Qintareh,非平民,成人 - 男,Idlib,Kafroumeh,2015-12-10,射击
21,Hani Khairallah Jbaneej,平民,成人 - 男性,Idlib,Kafroumeh,2015-12-10,射击
22,Ahmad Mohammad al-Shartah,非民事,成人 - 男性,Idlib,Kafroumeh,2015-12-10,射击
23,Faisal al-Ahmad al-Khaleefe的妻子,平民,成人 - 女性,Deir Ezzor,Qourieh,2015-12-10,战机炮击
24,身份不明,平民,成年 - 男性,Deir Ezzor, Takaya,2015-12-10,绑架 - 执行
25,身份不明1,平民,成人 - 男性,Deir Ezzor,Tabya Jazera村,2015-12-10,绑架 - 执行
26, ,平民,成人 - 男性,Deir Ezzor,Tabya Jazera村,2015-12-10,绑架 - 执行
27,身份不明3,平民,成人 - 男性,Deir Ezzor,Tabya Jazera村,2015-12-10 ,绑架 - 执行
28,身份不明4,平民,成人 - 男性,Deir Ezzor,Tabya Jazera村,2015-12-10,绑架 - 执行
29,身份不明5, Deir Ezzor,Tabya Jazera村,2015-12-10,绑架 - 执行
30,Fayez Qabaqji,非民事,成人 - 男性,Lattakia,土库曼斯坦,2015-12-10,射击
31 ,Fahed al-Asali,非民间,成年男性,大马士革,Jobar,2015-12-09,拍摄
32,Amoun Murad,平民,成人 - 女性,Idlib,Jisr Shagour:Mraand,2015-12 -09,战机炮击
33,Kafa Mezweq,平民,成人 - 女性,Idlib,Jisr Shagour:Mraand,2015-12-09,战机炮轰
34,Hala Mohammad, Idlib,Jisr Shagour:Mraand,2015-12-09,Warplane shelling
35,Ahmad Mezweq,Civilian,Child - Male,Idlib,Jisr Shagour:Mraand,2015-12-09,Warplane shelling
36 ,Ahlam Mezweq,平民,儿童 - 女性,Idlib,Jisr Shagour:Mraand,2015-12-09,Warplane shellling
37,Adnan Hussain Haj Kheder,Civilian,Child - Male,Idlib,Jisr Shagour:Mraand,2015 -12-09,战机轰击
38,侯赛因妻子Haj Kheder,平民,成人 - 女性,Idlib,Jisr Shagour:Mraand,2015-12-09,战机炮轰
39,侯赛因哈吉的女儿Kheder 1,平民,儿童 - 女性,Idlib,Jisr Shagour:Mraand,2015-12-09,Warplane shelling
40,Muhammad Muhammad al-Aoutani,Civilian,Adult - Male,大马士革郊区,Hamouria,2015-12 -09,战机轰击
41,Ibrahim al-Shami,平民,成年 - 男性,大马士革郊区,Hamouria,2015-12-09,战机轰击
42,Tahsin al-Durra,男,大马士革郊区,Douma,2015-12-09,战机炮击
43,Samer Safaya,平民,成人 - 男,大马士革郊区,Hamouria,2015-12-09,战机炮轰
44,Muhammad al-Qassir,平民,儿童 - 男,大马士革郊区,Hamouria,2015-12-09,战机炮轰
45,Ibtisam Abdlunaser al-Khatib,平民,儿童 - 女,大马士革郊区,Hamouria, 09,战机炮击
46,Tuqa Saria al-Zein,平民,儿童 - 女性,大马士革郊区,Hamouria,2015-12-09,战机轰击
47,Hadi Darwish,大马士革郊区,Hamouria,2015-12-09,战机轰击
48,Ghalia Abdulnaser al-Khatib,平民,儿童 - 女性,大马士革郊区,Hamouria,2015-12-09,Warplane炮轰
49, Yamen Amin Abbas,平民,儿童 - 男,大马士革郊区,Hamouria,2015-12-09,战机炮轰
50,Muhammad Wasim al-Kharboutli,平民,成年 - 男性,大马士革郊区, 09,战机炮击
51,Muhammad Ismael al-Khatib,平民,成人 - 男性,大马士革郊区,Hamouria,2015-12-09,战机炮击
52,Ismael Saeid al-Khatib, - 男,大马士革郊区,Hamouria,2015-12-09,战机炮轰
53,Saeid Abd al-Jawad,平民,成年 - 男性,大马士革郊区,Hamouria,2015-12-09,Warplane shelling
54,Abdulmoein al-Zein,Civilian,Adult - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shellling
55,Unidentified 1,Civilian,Adult - Male,Damascus Suburbs,Hamouria, -09,战机轰击
56,身份不明2,平民,成人 - 男性,大马士革郊区,Hamouria,2015-12-09,战机炮轰
57,身份不明3,平民,成人 - 男,大马士革郊区,Hamouria,2015-12-09,Warplane shelling
58,Mohammd Omar al-Deirani,非民间,成人 - 男性,大马士革郊区,Douma,2015-12-09,炮轰
59,女儿侯赛因Haj Kheder 2,平民,儿童 - 女性,Idlib,Jisr Shagour:Mraand,2015-12-09,战机炮轰
60,Ramez Shaher Qadour,平民,儿童 - 男,大马士革郊区,Hamouria, 12-09,战机炮击
61,Yazan Shaher Qadour,平民,儿童 - 男,大马士革郊区,Hamouria,2015-12-09,战机炮击
62,Sham Ahmad Qadour,平民, ,大马士革郊区,Hamouria,2015-12-09,战机炮轰
63,Ibraheem Ahmad Qadour,平民,儿童 - 男性,大马士革郊区,Hamouria,2015-12-09,战机炮轰
64,Fatemah Qadour,Civilian,Adult - 女,大马士革郊区,Hamouria,2015-12-09,战机炮轰
65,Houriah al-Aqra,平民,成人 - 女性,大马士革郊区,Hamouria,2015-12-09,Warplane炮击
66,Shahed al-Yousef,民用,儿童 - 女性,大马士革郊区,Hamouria,2015-12-09,战机炮轰
67,Faridah Qalla,平民,成年女性,大马士革郊区,Hamouria ,2015-12-09,战机轰击
68,Abo Eisa,非民事,成人 - 男性,大马士革,Yarmuk阵营,2015-12-09,射击
69,Mohammad Ataya Hadeideh,成人 - 男性,大马士革郊区,Saqba,2015-12-09,战机炮轰
70,Mohammad Abdullah Ali Raslan,非平民,成人 - 男性,大马士革郊区,Douma,2015-12-09,射击
71,Ahmad Khaled al-Ayoub,非民事,成人 - 男性,Idlib,Al-Tih镇,2015-12-09,拍摄
72,Salem Abo Saeid,非平民,成人 - Idlib,Saraman,2015-12-09,拍摄
73,Muneeb Abdul Baset al-Shawarghi,非民间,成人 - 男性,Idlib,Maarshamsha,2015-12-09,拍摄
74,Mohammad Ahmad al-Alayan,Civilian,Adult - Male,Hama,Kafrzita,2015-12-09,Warplane shellling
75,Bahaa Eddin al-Hamwi,Non-Civilian,Adult - Male,Damascus Suburbs,Douma, 12-09,射击
76,Saeid Smoad,非公民,成人 - 男性,大马士革郊区,Douma,2015-12-09,拍摄
77,Basheer Mahmoud Shihab,男,大马士革郊区,Douma,2015-12-09,拍摄
78,身份不明,文职,成人 - 男,Homs,Palmyra,2015-12-09,战机轰击
79,Ahmad Hamze Layla,平民,儿童 - 男,阿勒颇,阿南达,2015-12-09,战机炮轰
80,Abdul Wahhab Hsain,平民,成年 - 男性,Idlib,Jisr Shagour:Najieh,2015-12-08,Warplane shelling
81,Khaled Khalaf al-Zubi,Civilian,Adult - Male,Daraa,Jassim,2015-12-08,Warplane shelling
82,Hameede Hamed al-Haririal-Haishan平民,成人 - 女性,Daraa,Sheikh Miskeen,2015-12-08,炮轰
83,Ziyad Sayel al-Mreheel,非民事,成人 - 男性,Daraa,Dael,2015-12-08, b $ b 84,Ahmad Abdul Ilah al-Dairi,Civilian,Adult - Male,Daraa,Sheikh Miskeen,2015-12-08,拘留 - 酷刑
85,Noah Jaqmour,非侨民,成人 - 男性,Idlib ,Ariha,2015-12-08,射击
86,Mahmoud Beshe,平民,儿童 - 男,阿勒颇,Salheen,2015-12-08,Warplane炮轰
87,Omar Sbainati,男,大马士革郊区,Marj,2015-12-08,战机炮击
88,Meryam al-Jassem,平民,成人 - 女性,大马士革郊区,Marj,2015-12-08,Warplane炮轰
89 ,不明身份,平民,成人 - 女性,哈马,德洛尔al-Hemer,2015-12-08,战机炮轰
90,Hatem Uday Akashe,平民,儿童 - 男,Daraa,Jassim,战斗炮轰
91,Waddah Yaseen al-Ghazzawi,平民,成人 - 男性,Daraa,Sheikh Miskeen,2015-12-08,拘留 - 酷刑
92,Mohammad Sami al-Mahmoud,男,阿勒颇,Kafrahamreh,2015-12-08,战机轰击
93,Haloum al-Aas,平民,成年 - 男性,阿勒颇,Kafrahamreh,2015-12-08,Warplane炮轰
94,Maroush Abdo al-Mahmoud,Civilian,Adult - Female,Aleppo,Kafrahamreh,2015-12-08,Warplane shelling
95,Samirah Abdo al-Mahmoud,Civilian,Adult - Female,Aleppo,Kafrahamreh, ,战机炮击
96,沙巴Sehreej,平民,成人 - 女性,阿勒颇,Kafrahamreh,2015-12-08,战机轰击
97,身份不明,平民,成年人 - 男性,Aleppo,Kafrahamreh, 12-08,战机炮击
98,Abduljalil al-Mahmoud,平民,儿童 - 男,阿勒颇,Kafrahamreh,2015-12-08,战机轰击
99,Hala al-Mahmoud,女,阿勒颇,Kafrahamreh,2015-12-08,战机轰击
100,Yaser Yaser al-Mahmoud,平民,孩子 - 男,阿勒颇,Kafrahamreh,2015-12-08,Warplane炮轰
101, Abdulraheem al-Hamoud,非民事,成人 - 男性,阿勒颇,Batbo,2015-12-08,射击
102,Ahmad Hanouf,非民事,成人 - 男性,Lattakia,Jabla,2015-12-08 ,射击
103,Fadi Subhi al-Omar,非平民,成人 - 男性,Idlib,Binnish,2015-12-08,射击
104,Mohammad Nour Abdulla al-Aaraj,成人 - 男,Idlib,有,2015-12-08,射击
105,Mohammad Ibraheem al-Ali,非民事,成人 - 男,Idlib,Kafrsijneh,2015-12-08,拍摄
106,Mulham Ahmad Qeetaz,Non-Civilian,Adult - Male,Idlib,Maart Numan,2015-12-08,Shooting
107,Murad Mohammad Qeetaz,非民事,成人 - 男性,Idlib,Maart Numan,2015 -12-08,射击
108,Abdul Hameed Musa al-Gharibi,非民事,成人 - 男性,Idlib,Kafrauaid,2015-12-08,拍摄
109,Mohammad Badran,Civilian,Adult - 男,Daraa,Khirbet Ghazaleh,2015-12-08,拘留 - 酷刑
110,Mohammad Natheir黑人,平民,成年 - 男性,大马士革,米丹,2015-12-08,拘留 - 酷刑
111,身份不明,平民,成人 - 女性,Raqqa,Garimat Huzeima,2015-12-08,战机炮轰
112,身份不明,平民,儿童 - 男,大马士革郊区,Madaya,2015-12-08,其他
113,不明身份1,平民,成年人 - 男性,大马士革,Erbeen,2015-12-08,炮轰
114,身份不明2,平民,成年 - 男性,大马士革,炮轰
115,Mohammad Ahmad Abd Rabuh,平民,儿童 - 男,大马士革郊区,Hamouria,2015-12-08,炮轰
116,从al-Jebbah家庭,平民,儿童 - 男,大马士革郊区,Harasta,2015-12-08,炮轰
117,Ibraheem Saleh al-Khateeb,平民,成年 - 男性,Daraa,Enkhel,2015-12-08,战机轰炸
118,Fatemah al-Jubah Ji,平民,成人 - 女性,大马士革郊区,Harasta,2015-12-08,炮轰
119,Ismael Khaled蝙蝠侠al-Zgheer,平民,成年 - 男性,Homs,Palmyra,2015-12-08,Warplane炮轰
120,Zaher al-Homsi,非民间,成人 - 男性,哈马,2015-12-08,射击
121,Ahmad Hamdo al-Hallaq,非民间,成年 - Hama,Soran,2015-12-08,拍摄
122,Omar al-Hsain,非民间,成人 - 男性,哈马,2015-12-08,拍摄
123,Mohammad Abdul Rahman Reslan ,非民间,成人 - 男,阿勒颇,2015-12-08,射击
124,Slaiman Shaghal,平民,儿童 - 男,阿勒颇,阿南达,2015-12-08,战机炮轰
125,Yazan Hassan Hsain,非平民,成人 - 男性,Idlib,Kafryhmoul,2015-12-07,射击
126,Suleiman Waleed al-Ayanah,平民,成人 - 男性,Damascus Suburbs,Douma, 12-07,炮轰
127,Huda al-Aani,平民,成人 - 女性,代尔Ezzor,Ardi,2015-12-07,战机轰击
128,Huda al-Aani的儿子,儿童 - 男,代尔Ezzor,阿尔迪,2015-12-07,战机轰击
129,Khaled Konbel,非民事,成人 - 男性,拉塔基亚,土库曼斯坦,2015-12-07,拍摄
130,Ahmad Abo al-Wared,非民事,成人 - 男性,大马士革郊区,Daraya,2015-12-07,拍摄
131,Omar Ali al-Ekrah,非公民,成人 - 男性,大马士革郊区,Douma,2015-12-07,射击
132,Mohammad Majed Kabarah,平民,儿童 - 男性,大马士革郊区,Zamalka,2015-12-07,炮轰
133,Om Jameel Kheito,成人 - 女,大马士革郊区,Zabadany,2015-12-07,爆炸
134,Omar Mustafa Jdeid,平民,成人 - 男性,大马士革郊区,马达亚,2015-12-07,爆炸
135, Wael MahmoudIstanbouli,平民,成年人 - 男性,大马士革郊区,Madaya,2015-12-07,爆炸
136,Hasan Ahmad al-Khateeb,平民,成年 - 男性,Aleppo,Kafrahamreh, 2015-12-07,战机炮击
137,阿布杜拉斋月,平民,成年 - 男性,阿勒颇,Kafrahamreh,2015-12-07,战机轰击
138,Hamdo斋月,平民,阿勒颇,Kafrahamreh,2015-12-07,战机轰击
139,Raed斋月,平民,成人 - 男,阿勒颇,Kafrahamreh,2015-12-07,战机轰击
140,Aamer斋月,成人 - 男,阿勒颇,Kafrahamreh,2015-12-07,战机炮轰
141,穆罕默德Salem al-Mahmoud,平民,成人 - 男,阿勒颇,Kafrahamreh,2015-12-07,战机炮轰
142,Yehya Qasemo,非民间,成人 - 男性,哈马,Al-Sermenieh,2015-12-07,射击
143,Hasan Ahmad al-Hardan,平民,成年 - 男性,Aleppo,Salheen, 12-07,战机炮击
144,Ayda al-Hasan,平民,成人 - 女性,阿勒颇,Salheen,2015-12-07,战机炮击
145,Sahar Hamwi,阿勒颇,Salheen,2015-12-07,战机轰击
146,阿卜杜勒·哈米德苏丹,平民,成人 - 男性,阿勒颇,Hulluk,2015-12-07,战机轰击
147,Bilal Mahmoud, ,儿童 - 男,阿勒颇,Hulluk,2015-12-07,战机炮轰
148,撒哈拉Ghazal al-Hamwi,平民,成人 - 女性,阿勒颇,Hulluk,2015-12-07,Warplane炮轰
149,Fatme Ahmad al-Jasem,平民,成人 - 女性,Aleppo,Hulluk,2015-12-07,战机炮轰
150,身份不明,平民,儿童 - 男,阿勒颇,Hulluk,2015-12-07 ,战机炮击
151,哈桑Mohammad Rammo,平民,成人 - 男,阿勒颇,苏卡里邻里,2015-12-07,战机轰击
152,Hajar Mahmoud Akeel,平民,儿童 - 女, Sukkari邻里,2015-12-07,战机轰击
153,Shaymaa Mahmoud Akeel,平民,儿童 - 女,阿勒颇,苏卡里邻里,2015-12-07,战机轰击
154,Abed Seyam,Non - 平民,成人 - 男性,大马士革,Yarmuk阵营,2015-12-07,战机炮轰
155,身份不明,平民,成人 - 男,阿勒颇,2015-12-07,炮轰
156, Abdul Rawof Mohammad,非民间,成人 - 男性,阿勒颇,2015-12-07,拍摄
157,Waleed Hamoush,非民间,成人 - 男性,阿勒颇,2015-12-07,拍摄
158,Abdulkareem al-Suleiman,非民事,成人 - 男性,阿勒颇,2015-12-07,射击
159,Mohammad al-Qarrat,非民事,成人 - 男性,Aleppo ,, 2015-12-07,射击
160,Abdullah al-Melhem al-Abdullah,非民事,成人 - 男性,Aleppo ,, 2015-12-07,射击
161,Yaser Saeed Ghanoum,Non - 民间,成人 - 男性,阿勒颇,2015-12-07,射击
162,阿里苏丹al-Samouri,非民事,成人 - 男性,Daraa,Jamleh,2015-12-07,绑架 - 执行
163,Yousef Sultan al-Samouri,非民事,成人 - 男性,Daraa,Jamleh,2015-12-07,绑架 - 执行
164,Rami al-Sayo,非民事,成人 - 男,Deir Ezzor ,, 2015-12-07,绑架 - 执行
165,Akram al-Merie,平民,成年 - 男性,Deir Ezzor ,, 2015-12-07,绑架 - 执行
166 ,Adnan Saleh al-Shaqran,非民事,成人 - 男性,Daraa,Fuqia,2015-12-07,拍摄
167,Alaa Wael Sadaqa,非民间,成人 - 男性,Daraa,Fuqia, 12-07,射击
168,Oqba Jad al-Kareem al-Hareeri,非平民,成人 - 男性,Daraa,Fuqia,2015-12-07,射击
169,Ali Abdul Ghani al- Shaqran,非平民,成人 - 男性,Daraa,Fuqia,2015-12-07,射击
170,Bushra Ahmad Adeel al-Hareeri,平民,成人 - 女性,Daraa,Bassr Al-Hareer,2015-12 -07,战机轰击
171,Hsain Sami Shawar,平民,成年 - 男性,Idlib,Jisr Shagour:Najieh,2015-12-07,战机轰击
172,Hsain Sami Shawar的妻子,成人 - 女性,Idlib,Jisr Shagour:Najieh,2015-12-07,Warplane shelling
15k +行的这个,因为你可能注意到一些地方有相同的条目几次。我的工作流是从sqlite数据库的数据到这个大csv。之后,我过滤了两倍的条目,所以我只是得到每个地方/省一次。因此,可以减少geocoder的查询(我是天真的,认为你没有一个限制)。我现在的问题是,我有两个数据集,我不能放在一起,因为简单的搜索和替换所有条目与纬度/经度信息将仍然是一个困难和时间浪费的任务。也因为条目数字不匹配。
我有两个想法,我为他们两个我没有线索如何到那里,因为我是新的python,我一整天在这个数据。
- 使用(省/地区,纬度,经度)自动执行搜索和替换过程(省/地区)
-
有几个人在同一天死在同一个地方。我可以在技术上总结它们,所以整个数据变得更小(我应该这样做。在SQLite oder在Python与csv)。所以我可以查询这个数据到geocoder,所以我有一个完整的文件。像这样,我将查询省和地理编码器的区域:
rowid,Value_by_People,状态,省, Date_of_Death,Cause_of_Death
1,13,平民,Daraa,Sawara,2015-12-10,战机炮击
2,50,Civilian,Daraa,Sawara,2015-12-7,拍摄
感谢您的建议
EDIT1
query =','。 (row ['Province'],row ['''],row ['''],row ['国家']))
打印(查询)
尝试:
地址(纬度,经度)= geolocator.geocode(查询)
:
address,(latitude,longitude)= geolocator.geocode(errorquery)
#latitude ='N / A'
#longitude ='N / A'
编辑3
我尝试了更改, / p>
import csv
来自geopy.geocoders import GoogleV3
geolocator = GoogleV3需要一些参数
lookups = {}#在循环上面声明这个循环
global tempquery
全局纬度,经度
def lookup_location(query,errorquery,lookups)
tempquery = query
try:
address,(latitude,longitude)= lookups [query]
except KeyError:#new lookup
try:
#address,(latitude,longitude)= geolocator.geocode(query)
address,(latitude,longitude)= lookups [errorquery]
except:#should might try to catch specific exceptions
#address = latitude = longitude = None
try:
address,(latitude,longitude)= geolocator.geocode(query)
#address,(latitude,longitude)= lookups [errorquery ]
except KeyError:#new lookup
try:
address,(latitude,longitude)= geolocator.geocode(errorquery)
tempquery = errorquery
except:
address = latitude = longitude ='None'
tempquery = errorquery
lookups [tempquery] = address,(latitude,longitude)
返回地址,纬度,经度
with open('151213_Martyrs_filtered_civilian_2015_with_country.csv','rb')as csvinput:
with open('151213_locations_filtered_fiexedwith_cities_country.csv','w')as csvoutput:
output_fieldnames = [' Name','Status','Sex','Country','Province','Area','Date_of_Death','Cause_of_Death','Latitude','Longitude']
writer = csv.DictWriter(csvoutput ,delimiter =',',fieldnames = output_fieldnames)
reader = csv.DictReader(csvinput)
读取器中的行:
你必须用csv列名称替换dict项目
query =','。join(str(x)for x in(row ['Country'],row ['Province'],row ['Area']))
errorquery = '.join(str(x)for x in(row ['Country'],row ['Province'],row ['Province']))
lookup_location(query,errorquery,lookups)
output_row = {}
output_row ['Name'] = row ['Name']
output_row ['Status'] = row ['Status']
output_row ['Sex'] = row ['Sex']
output_row ['Country'] = row ['Country']
output_row ['Province'] = row ['Province']
output_row ['Area'] = row ['Area']
output_row ['Date_of_Death'] = row ['Date_of_Death']
output_row ['Cause_of_Death'] = row ['Cause_of_Death']
output_row ['Latitude'] = 0
output_row ['Longitude'] = 0
writer.writerow(output_row)
出现这些错误
回溯(最近最后一次呼叫):
在< module>中的文件geopy_script_04_changes.py,第43行
lookup_location(query,errorquery,lookups)
文件geopy_script_04_changes.py,第21行,在lookup_location中
地址,(纬度,经度)= geolocator.geocode TypeError:'NoneType'object is not iterable
解决方案代码有点,所以它为我工作。感谢您的想法和帮助。
import csv
来自geopy.geocoders import GoogleV3
geolocator = GoogleV3()#其中需要一些参数
lookups = {}
with open('151213_Martyrs_filtered_civilian_2015_with_country.csv','rb')as csvinput:
with open('151213_output_martyrs_final.csv','w')as csvoutput:
output_fieldnames = ['Name','Status','Sex','Country',' ,'Date_of_Death','Cause_of_Death','Latitude','Longitude']
writer = csv.DictWriter(csvoutput, delimiter=',', fieldnames=output_fieldnames)
reader = csv.DictReader(csvinput )
for row in reader:
if row['Province'].split(' ', 1) == 'Damascus':
rowProv = \"Damascus\"
else:
rowProv = row['Province']
#here you have to replace the dict item by your csv column names
query = ','.join(str(x) for x in ( rowProv, row['Area']))
try:
address, (latitude, longitude) = lookups[query]
except KeyError: # new lookup
try:
query = ','.join(str(x) for x in (rowProv, rowProv))
address, (latitude, longitude) = lookups[query]
print(' lookup')
except KeyError: # search
try:
query = ','.join(str(x) for x in (rowProv, row['Area'])) $b $b address, (latitude, longitude) = geolocator.geocode(query)
except: # error
query = ','.join(str(x) for x in (rowProv, rowProv)) $ b$b address, (latitude, longitude) = geolocator.geocode(query)
lookups[query] = address, (latitude, longitude)
print(query)
# here is the writing section
output_row = {}
output_row['Name'] = row['Name']
output_row['Status'] = row['Status'] $b$ b output_row['Sex'] = row['Sex']
output_row['Country'] = row['Country']
output_row['Province'] = row['Province'] $b $b output_row['Area'] = row['Area']
output_row['Date_of_Death'] = row['Date_of_Death']
output_row['Cause_of_Death'] = row['Cause_of_Death'] $ b$b output_row['Latitude'] = latitude
output_row['Longitude'] = longitude
writer.writerow(output_row)
I have this CSV file which i'm feeding with this python script
import csv from geopy.geocoders import OpenCage geolocator = OpenCage() #here some parameters are needed with open('/Users/Ian/Desktop/Test02/151213_2015_martyrs_year_filtered_areas.csv', 'rb') as csvinput: with open('151213_locations_filtered_opencage.csv', 'w') as csvoutput: output_fieldnames = ['Province','Area', 'Country','Latitude','Longitude'] writer = csv.DictWriter(csvoutput, delimiter=',', fieldnames=output_fieldnames) reader = csv.DictReader(csvinput) for row in reader: #here you have to replace the dict item by your csv column names query = ','.join(str(x) for x in (row['Country'],row['Province'],row['Area'])) print(query) try: address, (latitude, longitude) = geolocator.geocode(query) except: latitude = 'N/A' longitude = 'N/A' #here is the writing section output_row = {} output_row['Province'] = row['Province'] output_row['Area'] = row['Area'] output_row['Country'] = row['Country'] output_row['Latitude'] = latitude output_row['Longitude'] = longitude writer.writerow(output_row)
CSV FILE Excerpt
Province,Area,Country Aleppo,Jarablus,Syria Aleppo,,Syria Aleppo,Kafrnaya,Syria Aleppo,Bazzaa,Syria Aleppo,Anadan,Syria Aleppo,Salheen,Syria Aleppo,Kafrahamreh,Syria Aleppo,Batbo,Syria Aleppo,Hulluk,Syria Aleppo,Sukkari neighborhood,Syria Aleppo,"Ein Arab ""Kobani"": Srain",Syria Aleppo,Bab,Syria Aleppo,Tel Rifaat,Syria Aleppo,Izaz,Syria Aleppo,Sfaireh,Syria Aleppo,Hritan,Syria Aleppo,Manbej,Syria Aleppo,Karm Bitar,Syria Aleppo,Atarib,Syria Aleppo,Neirab,Syria Aleppo,Afrin: Mariameen,Syria Aleppo,Zerbeih Town,Syria Aleppo,Sakhour,Syria Aleppo,Tal Abad,Syria Aleppo,Tal Arran,Syria Aleppo,Talqrah,Syria Aleppo,Tqad,Syria Aleppo,Darat Azza,Syria Aleppo,Bayanoun,Syria Aleppo,Misakan,Syria Aleppo,Qosaileh,Syria Aleppo,Mashatieh neighborhood,Syria Aleppo,Kabbasin,Syria Aleppo,Harjalleih,Syria Aleppo,Bab Road neighborhood,Syria Aleppo,Qanater village,Syria Aleppo,Maskaneh,Syria Aleppo,Jeb el-Qibba,Syria Aleppo,Hwer al-Aes,Syria Aleppo,"Ein Arab""Kobani""",Syria Aleppo,Anjareh,Syria Aleppo,Hayyan,Syria Aleppo,Sheikh Saeed,Syria Aleppo,Liramon,Syria Aleppo,Karam Muayassar,Syria Aleppo,Tel Daman: Tel Maseh village,Syria Aleppo,Eibeen Simon,Syria Aleppo,Deir Hafir,Syria Aleppo,Sheikh Ali village,Syria Aleppo,Afrin,Syria Aleppo,Khan Toman,Syria Aleppo,Rasm al-Aboud village,Syria Aleppo,Hulluk: Ein el-Tal,Syria Aleppo,Khan el-Asal,Syria Aleppo,Alshyoukh Alfoqani,Syria Aleppo,Mare,Syria Aleppo,Der Jamal,Syria Aleppo,Mkahleh,Syria Aleppo,Zebdieh,Syria Aleppo,Ansari,Syria Aleppo,Bustan el-Qassr,Syria Aleppo,Eastern Ansari,Syria Aleppo,Banjaira,Syria Aleppo,Kallaseh,Syria Aleppo,Tal Memo,Syria Aleppo,Museijrat al-Bosheikh,Syria Aleppo,Aziziah,Syria Aleppo,Salahiddin,Syria Aleppo,Tel Rifaat: Herpel,Syria Aleppo,Shokaileh,Syria Aleppo,Kafrobeid,Syria Aleppo,Jazraya,Syria Aleppo,Fardous,Syria Aleppo,Mestaha,Syria Aleppo,Bab Neirab,Syria Aleppo,Magaier,Syria Aleppo,Karam el-Nuzha,Syria Aleppo,Tal Hdia,Syria Aleppo,Talhia,Syria Aleppo,Karam Al-Tarrab,Syria Aleppo,Zerbeih town,Syria Aleppo,Tel Daman,Syria Aleppo,Great Orme,Syria Aleppo,Ritian,Syria Aleppo,Barkoum,Syria Aleppo,Sheikh Maksoud,Syria Aleppo,Ihres,Syria Aleppo,Sfaireh: Azzan mountain,Syria Aleppo,Hader village,Syria Aleppo,Mraij,Syria Aleppo,Deir Hafir: Tel Ayoub,Syria Aleppo,Abtin village,Syria Aleppo,Kafrnoran,Syria Aleppo,Deir Hafir: Sheikh Ahmed village,Syria Aleppo,Rasm al-Sheikh,Syria Aleppo,Ezaa Neighborhood,Syria Aleppo,Zitan,Syria Aleppo,Kfarkarmin village,Syria Aleppo,Blas,Syria Aleppo,Seif El-Dawla,Syria Aleppo,Bab el-Faraj,Syria Aleppo,Teljabin,Syria Aleppo,Rjaileh,Syria Aleppo,Kafra,Syria Aleppo,Ziyareh,Syria Aleppo,Sfaireh: Mgairat Shibli village,Syria Aleppo,Talaarn,Syria Aleppo,Sahareh,Syria Aleppo,Shaar,Syria Aleppo,Meng,Syria Aleppo,Mowasalat,Syria Aleppo,Qadi Askar,Syria Aleppo,Mashad,Syria Aleppo,Izaz: Kfarkplpin,Syria Aleppo,Rashideen,Syria Aleppo,Marja,Syria Aleppo,Kafin,Syria Aleppo,Dabik,Syria Aleppo,Suleiman al-Halabi,Syria Aleppo,Mayer,Syria Aleppo,Tlaleen,Syria Aleppo,Hamdania,Syria Aleppo,Tel Tokan,Syria Aleppo,Tel Shgaib,Syria Aleppo,Tadif,Syria Aleppo,Manbei: Deir Jamal,Syria Aleppo,Qubtan el-Jabal,Syria Aleppo,Ahtimlat,Syria Aleppo,Majas Village,Syria Aleppo,Masaken al-Sabeel,Syria Aleppo,Sheikh Khader,Syria Aleppo,Masharq,Syria Aleppo,Bshentreh village,Syria Aleppo,Hur village,Syria Aleppo,Ein Arab: Srain,Syria Aleppo,Amerieh,Syria Aleppo,Safira: Talaran,Syria Aleppo,Jaina,Syria Aleppo,Ashrafieh,Syria Aleppo,Qustal Harami,Syria Aleppo,Marestit el-Khan,Syria Aleppo,Hamidiya village,Syria Aleppo,Muyassar neighborhood,Syria Aleppo,Zyade village,Syria Aleppo,Bab: Braij Palace village,Syria Aleppo,Um al-Hosh village,Syria Aleppo,Darat Azza: Mount Simon: Deir Simeon Village,Syria Aleppo,Arran,Syria Aleppo,Shwehneh Mountain,Syria Aleppo,Masakin Hanano,Syria Aleppo,Kafrdaal,Syria Aleppo,Hoteh,Syria Aleppo,Rabiea,Syria Aleppo,bab,Syria Aleppo,Karam el-Baik neighborhood,Syria Aleppo,Madaein Kabira,Syria Aleppo,Maadi neighborhood,Syria Aleppo,Jamiat al-Zahraa,Syria Aleppo,Maarat Artik,Syria Aleppo,Karm Al-Afandi,Syria Aleppo,New Aleppo,Syria Aleppo,Deir Hafir: Rasm Harmel,Syria Aleppo,"Ein Arab ""Kobani""",Syria Aleppo,Absmo,Syria Aleppo,Deir Hassan,Syria Aleppo,Talkrah,Syria Aleppo,Simon Mount: Mansoura,Syria Aleppo,Atarib: Twama,Syria Aleppo,Kafarnaha,Syria Aleppo,Bab Qinnasrin,Syria Aleppo,Pedro Mount,Syria Aleppo,Dahrat Awad,Syria Aleppo,Qirliq neighborhood,Syria Aleppo,Um Hosh,Syria Aleppo,Baideen,Syria Aleppo,Akhtareen,Syria Aleppo,Izaz: Soran town,Syria Aleppo,Harableh,Syria Aleppo,Bab: Abu Taltal village,Syria Aleppo,Bareh Azzawi,Syria Aleppo,Malha,Syria Aleppo,Ezaa neighborhood,Syria Aleppo,Kafernasaeh,Syria Aleppo,Karam el-Jabal,Syria Aleppo,Tadeel,Syria Aleppo,Abo Mjaher,Syria Aleppo,al-Aes,Syria Aleppo,khalsa,Syria Aleppo,Arjileh,Syria Aleppo,Alas,Syria Aleppo,Khalsa,Syria Aleppo,Jisr el-Hajj,Syria Aleppo,Qataneh,Syria Aleppo,Ahmadia,Syria Aleppo,Garliq,Syria Aleppo,Sheikh Najjar,Syria
But the original csv looks like this
rowid,Name,Status,Sex,Province,Area,Date_of_Death,Cause_of_Death 1,Hasan Ali Saad al-Hareeri ,Civilian,Adult - Male,Daraa,Sawara,2015-12-10,Warplane shelling 2,Riham Adnan Swais ,Civilian,Adult - Female,Homs,Telbeiseh,2015-12-10,Shelling 3,Ammar Ahmad al-Njoam ,Civilian,Adult - Male,Aleppo,Jarablus,2015-12-10,Explosion 4,Yaseen Slaiman al-Salkhadi ,Civilian,Adult - Male,Daraa,Jassim,2015-12-10,Warplane shelling 5,Ayman Noman Qanatra ,Civilian,Adult - Male,Daraa,Jassim,2015-12-10,Warplane shelling 6,Abdul Kareem Mohammad al-Tamki ,Civilian,Adult - Male,Daraa,Sheikh Miskeen,2015-12-10,Warplane shelling 7,Ahmad Mohammad al-Tamki ,Civilian,Child - Male,Daraa,Sheikh Miskeen,2015-12-10,Warplane shelling 8,Hamze Mohammad al-Tamki ,Civilian,Adult - Male,Daraa,Sheikh Miskeen,2015-12-10,Warplane shelling 9,Mohammad Ahmad al-Khaleel ,Non-Civilian,Adult - Male,Daraa,Sheikh Miskeen,2015-12-10,Shelling 10,Abdul Kareem Abdul Lateef al-Mohammad ,Non-Civilian,Adult - Male,Hama,Lattamna,2015-12-10,Shooting 11,Mahdi Basem Qatteni ,Non-Civilian,Adult - Male,Idlib,Khan Sheikhoun,2015-12-10,Shooting 12,Ahmad Ibraheem al-Sayed Omar ,Civilian,Adult - Male,Aleppo,,2015-12-10,Warplane shelling 13,Unidentified ,Civilian,Child - Male,Aleppo,Kafrnaya,2015-12-10,Warplane shelling 14,Unidentified 1 ,Civilian,Adult - Female,Aleppo,Bazzaa,2015-12-10,Warplane shelling 15,Unidentified 2 ,Civilian,Child - Male,Aleppo,Bazzaa,2015-12-10,Warplane shelling 16,Unidentified 3 ,Civilian,Child - Male,Aleppo,Bazzaa,2015-12-10,Warplane shelling 17,Mohammad Ahmad al-Farhoud ,Civilian,Adult - Male,Idlib,Telminis,2015-12-10,Shooting 18,Yousef al-Saleh ,Non-Civilian,Adult - Male,Idlib,Kafroumeh,2015-12-10,Shooting 19,Basel Hsain al-Knoah ,Non-Civilian,Adult - Male,Idlib,Kafroumeh,2015-12-10,Shooting 20,Basel Abdul Rahman Qintareh ,Non-Civilian,Adult - Male,Idlib,Kafroumeh,2015-12-10,Shooting 21,Hani Khairallah Jbaneej ,Non-Civilian,Adult - Male,Idlib,Kafroumeh,2015-12-10,Shooting 22,Ahmad Mohammad al-Shartah ,Non-Civilian,Adult - Male,Idlib,Kafroumeh,2015-12-10,Shooting 23,wife of Faisal al-Ahmad al-Khaleefe ,Civilian,Adult - Female,Deir Ezzor,Qourieh,2015-12-10,Warplane shelling 24,Unidentified ,Civilian,Adult - Male,Deir Ezzor,Takaya,2015-12-10,Kidnapping - Execution 25,Unidentified 1 ,Civilian,Adult - Male,Deir Ezzor,Tabya Jazera village,2015-12-10,Kidnapping - Execution 26,Unidentified 2 ,Civilian,Adult - Male,Deir Ezzor,Tabya Jazera village,2015-12-10,Kidnapping - Execution 27,Unidentified 3 ,Civilian,Adult - Male,Deir Ezzor,Tabya Jazera village,2015-12-10,Kidnapping - Execution 28,Unidentified 4 ,Civilian,Adult - Male,Deir Ezzor,Tabya Jazera village,2015-12-10,Kidnapping - Execution 29,Unidentified 5 ,Civilian,Adult - Male,Deir Ezzor,Tabya Jazera village,2015-12-10,Kidnapping - Execution 30,Fayez Qabaqji ,Non-Civilian,Adult - Male,Lattakia,Turkmen mount,2015-12-10,Shooting 31,Fahed al-Asali ,Non-Civilian,Adult - Male,Damascus,Jobar,2015-12-09,Shooting 32,Amoun Murad ,Civilian,Adult - Female,Idlib,Jisr Shagour: Mraand,2015-12-09,Warplane shelling 33,Kafa Mezweq ,Civilian,Adult - Female,Idlib,Jisr Shagour: Mraand,2015-12-09,Warplane shelling 34,Hala Mohammad ,Civilian,Adult - Female,Idlib,Jisr Shagour: Mraand,2015-12-09,Warplane shelling 35,Ahmad Mezweq ,Civilian,Child - Male,Idlib,Jisr Shagour: Mraand,2015-12-09,Warplane shelling 36,Ahlam Mezweq ,Civilian,Child - Female,Idlib,Jisr Shagour: Mraand,2015-12-09,Warplane shelling 37,Adnan Hussain Haj Kheder ,Civilian,Child - Male,Idlib,Jisr Shagour: Mraand,2015-12-09,Warplane shelling 38,Wife of Hussain Haj Kheder ,Civilian,Adult - Female,Idlib,Jisr Shagour: Mraand,2015-12-09,Warplane shelling 39,daughter of Hussain Haj Kheder 1 ,Civilian,Child - Female,Idlib,Jisr Shagour: Mraand,2015-12-09,Warplane shelling 40,Muhammad Muhammad al-Aoutani ,Civilian,Adult - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 41,Ibrahim al-Shami ,Civilian,Adult - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 42,Tahsin al-Durra ,Civilian,Adult - Male,Damascus Suburbs,Douma,2015-12-09,Warplane shelling 43,Samer Safaya ,Civilian,Adult - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 44,Muhammad al-Qassir ,Civilian,Child - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 45,Ibtisam Abdlunaser al-Khatib ,Civilian,Child - Female,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 46,Tuqa Saria al-Zein ,Civilian,Child - Female,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 47,Hadi Darwish ,Civilian,Child - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 48,Ghalia Abdulnaser al-Khatib ,Civilian,Child - Female,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 49,Yamen Amin Abbas ,Civilian,Child - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 50,Muhammad Wasim al-Kharboutli ,Civilian,Adult - Male,Damascus Suburbs,Mleha,2015-12-09,Warplane shelling 51,Muhammad Ismael al-Khatib ,Civilian,Adult - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 52,Ismael Saeid al-Khatib ,Civilian,Adult - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 53,Saeid Abd al-Jawad ,Civilian,Adult - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 54,Abdulmoein al-Zein ,Civilian,Adult - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 55,Unidentified 1 ,Civilian,Adult - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 56,Unidentified 2 ,Civilian,Adult - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 57,Unidentified 3 ,Civilian,Adult - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 58,Mohammd Omar al-Deirani ,Non-Civilian,Adult - Male,Damascus Suburbs,Douma,2015-12-09,Shelling 59,daughter of Hussain Haj Kheder 2 ,Civilian,Child - Female,Idlib,Jisr Shagour: Mraand,2015-12-09,Warplane shelling 60,Ramez Shaher Qadour ,Civilian,Child - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 61,Yazan Shaher Qadour ,Civilian,Child - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 62,Sham Ahmad Qadour ,Civilian,Child - Female,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 63,Ibraheem Ahmad Qadour ,Civilian,Child - Male,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 64,Fatemah Qadour ,Civilian,Adult - Female,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 65,Houriah al-Aqra ,Civilian,Adult - Female,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 66,Shahed al-Yousef ,Civilian,Child - Female,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 67,Faridah Qalla ,Civilian,Adult - Female,Damascus Suburbs,Hamouria,2015-12-09,Warplane shelling 68,Abo Eisa ,Non-Civilian,Adult - Male,Damascus,Yarmuk Camp,2015-12-09,Shooting 69,Mohammad Ataya Hadeideh ,Civilian,Adult - Male,Damascus Suburbs,Saqba,2015-12-09,Warplane shelling 70,Mohammad Abdullah Ali Raslan ,Non-Civilian,Adult - Male,Damascus Suburbs,Douma,2015-12-09,Shooting 71,Ahmad Khaled al-Ayoub ,Non-Civilian,Adult - Male,Idlib,Al-Tih town,2015-12-09,Shooting 72,Salem Abo Saeid ,Non-Civilian,Adult - Male,Idlib,Saraman,2015-12-09,Shooting 73,Muneeb Abdul Baset al-Shawarghi ,Non-Civilian,Adult - Male,Idlib,Maarshamsha,2015-12-09,Shooting 74,Mohammad Ahmad al-Alayan ,Civilian,Adult - Male,Hama,Kafrzita,2015-12-09,Warplane shelling 75,Bahaa Eddin al-Hamwi ,Non-Civilian,Adult - Male,Damascus Suburbs,Douma,2015-12-09,Shooting 76,Saeid Smoad ,Non-Civilian,Adult - Male,Damascus Suburbs,Douma,2015-12-09,Shooting 77,Basheer Mahmoud Shihab ,Non-Civilian,Adult - Male,Damascus Suburbs,Douma,2015-12-09,Shooting 78,Unidentified ,Civilian,Adult - Male,Homs,Palmyra,2015-12-09,Warplane shelling 79,Ahmad Hamze Layla ,Civilian,Child - Male,Aleppo,Anadan,2015-12-09,Warplane shelling 80,Abdul Wahhab Hsain ,Civilian,Adult - Male,Idlib,Jisr Shagour: Najieh,2015-12-08,Warplane shelling 81,Khaled Khalaf al-Zubi ,Civilian,Adult - Male,Daraa,Jassim,2015-12-08,Warplane shelling 82,"Hameede Hamed al-Hariri ""al-Haishan"" ",Civilian,Adult - Female,Daraa,Sheikh Miskeen,2015-12-08,Shelling 83,Ziyad Sayel al-Mreheel ,Non-Civilian,Adult - Male,Daraa,Dael,2015-12-08,Shooting 84,Ahmad Abdul Ilah al-Dairi ,Civilian,Adult - Male,Daraa,Sheikh Miskeen,2015-12-08,Detention - Torture 85,Noah Jaqmour ,Non-Civilian,Adult - Male,Idlib,Ariha,2015-12-08,Shooting 86,Mahmoud Beshe ,Civilian,Child - Male,Aleppo,Salheen,2015-12-08,Warplane shelling 87,Omar Sbainati ,Civilian,Child - Male,Damascus Suburbs,Marj,2015-12-08,Warplane shelling 88,Meryam al-Jassem ,Civilian,Adult - Female,Damascus Suburbs,Marj,2015-12-08,Warplane shelling 89,Unidentified ,Civilian,Adult - Female,Hama,Telool al-Hemer,2015-12-08,Warplane shelling 90,Hatem Uday Akashe ,Civilian,Child - Male,Daraa,Jassim,2015-12-08,Warplane shelling 91,Waddah Yaseen al-Ghazzawi ,Civilian,Adult - Male,Daraa,Sheikh Miskeen,2015-12-08,Detention - Torture 92,Mohammad Sami al-Mahmoud ,Civilian,Adult - Male,Aleppo,Kafrahamreh,2015-12-08,Warplane shelling 93,Haloum al-Aas ,Civilian,Adult - Male,Aleppo,Kafrahamreh,2015-12-08,Warplane shelling 94,Maroush Abdo al-Mahmoud ,Civilian,Adult - Female,Aleppo,Kafrahamreh,2015-12-08,Warplane shelling 95,Samirah Abdo al-Mahmoud ,Civilian,Adult - Female,Aleppo,Kafrahamreh,2015-12-08,Warplane shelling 96,Sabah Sehreej ,Civilian,Adult - Female,Aleppo,Kafrahamreh,2015-12-08,Warplane shelling 97,Unidentified ,Civilian,Adult - Male,Aleppo,Kafrahamreh,2015-12-08,Warplane shelling 98,Abduljalil al-Mahmoud ,Civilian,Child - Male,Aleppo,Kafrahamreh,2015-12-08,Warplane shelling 99,Hala al-Mahmoud ,Civilian,Child - Female,Aleppo,Kafrahamreh,2015-12-08,Warplane shelling 100,Yaser Yaser al-Mahmoud ,Civilian,Child - Male,Aleppo,Kafrahamreh,2015-12-08,Warplane shelling 101,Abdulraheem al-Hamoud ,Non-Civilian,Adult - Male,Aleppo,Batbo,2015-12-08,Shooting 102,Ahmad Hanouf ,Non-Civilian,Adult - Male,Lattakia,Jabla,2015-12-08,Shooting 103,Fadi Subhi al-Omar ,Non-Civilian,Adult - Male,Idlib,Binnish,2015-12-08,Shooting 104,Mohammad Nour Abdulla al-Aaraj ,Non-Civilian,Adult - Male,Idlib,Has,2015-12-08,Shooting 105,Mohammad Ibraheem al-Ali ,Non-Civilian,Adult - Male,Idlib,Kafrsijneh,2015-12-08,Shooting 106,Mulham Ahmad Qeetaz ,Non-Civilian,Adult - Male,Idlib,Maart Numan,2015-12-08,Shooting 107,Murad Mohammad Qeetaz ,Non-Civilian,Adult - Male,Idlib,Maart Numan,2015-12-08,Shooting 108,Abdul Hameed Musa al-Gharibi ,Non-Civilian,Adult - Male,Idlib,Kafrauaid,2015-12-08,Shooting 109,Mohammad Badran ,Civilian,Adult - Male,Daraa,Khirbet Ghazaleh,2015-12-08,Detention - Torture 110,Mohammad Natheir Darkal ,Civilian,Adult - Male,Damascus,Midan,2015-12-08,Detention - Torture 111,Unidentified ,Civilian,Adult - Female,Raqqa,Garimat Huzeima,2015-12-08,Warplane shelling 112,Unidentified ,Civilian,Child - Male,Damascus Suburbs,Madaya,2015-12-08,Other 113,Unidentified 1 ,Civilian,Adult - Male,Damascus,Erbeen,2015-12-08,Shelling 114,Unidentified 2 ,Civilian,Adult - Male,Damascus,Erbeen,2015-12-08,Shelling 115,Mohammad Ahmad Abd Rabuh ,Civilian,Child - Male,Damascus Suburbs,Hamouria,2015-12-08,Shelling 116,From al-Jebbah Family ,Civilian,Child - Male,Damascus Suburbs,Harasta,2015-12-08,Shelling 117,Ibraheem Saleh al-Khateeb ,Civilian,Adult - Male,Daraa,Enkhel,2015-12-08,Warplane shelling 118,Fatemah al-Jubah Ji ,Civilian,Adult - Female,Damascus Suburbs,Harasta,2015-12-08,Shelling 119,Ismael Khaled Batman al-Zgheer ,Civilian,Adult - Male,Homs,Palmyra,2015-12-08,Warplane shelling 120,Zaher al-Homsi ,Non-Civilian,Adult - Male,Hama,,2015-12-08,Shooting 121,Ahmad Hamdo al-Hallaq ,Non-Civilian,Adult - Male,Hama,Soran,2015-12-08,Shooting 122,Omar al-Hsain ,Non-Civilian,Adult - Male,Hama,,2015-12-08,Shooting 123,Mohammad Abdul Rahman Reslan ,Non-Civilian,Adult - Male,Aleppo,,2015-12-08,Shooting 124,Slaiman Shaghal ,Civilian,Child - Male,Aleppo,Anadan,2015-12-08,Warplane shelling 125,Yazan Hassan Hsain ,Non-Civilian,Adult - Male,Idlib,Kafryhmoul,2015-12-07,Shooting 126,Suleiman Waleed al-Ayanah ,Civilian,Adult - Male,Damascus Suburbs,Douma,2015-12-07,Shelling 127,Huda al-Aani ,Civilian,Adult - Female,Deir Ezzor,Ardi,2015-12-07,Warplane shelling 128,son of Huda al-Aani ,Civilian,Child - Male,Deir Ezzor,Ardi,2015-12-07,Warplane shelling 129,Khaled Konbel ,Non-Civilian,Adult - Male,Lattakia,Turkmen mount,2015-12-07,Shooting 130,Ahmad Abo al-Wared ,Non-Civilian,Adult - Male,Damascus Suburbs,Daraya,2015-12-07,Shooting 131,Omar Ali al-Ekrah ,Non-Civilian,Adult - Male,Damascus Suburbs,Douma,2015-12-07,Shooting 132,Mohammad Majed Kabarah ,Civilian,Child - Male,Damascus Suburbs,Zamalka,2015-12-07,Shelling 133,Om Jameel Kheito ,Civilian,Adult - Female,Damascus Suburbs,Zabadany,2015-12-07,Explosion 134,Omar Mustafa Jdeid ,Civilian,Adult - Male,Damascus Suburbs,Madaya,2015-12-07,Explosion 135,"Wael Mahmoud ""Istanbouli"" ",Civilian,Adult - Male,Damascus Suburbs,Madaya,2015-12-07,Explosion 136,Hasan Ahmad al-Khateeb ,Civilian,Adult - Male,Aleppo,Kafrahamreh,2015-12-07,Warplane shelling 137,Abdulla Ramadan ,Civilian,Adult - Male,Aleppo,Kafrahamreh,2015-12-07,Warplane shelling 138,Hamdo Ramadan ,Civilian,Adult - Male,Aleppo,Kafrahamreh,2015-12-07,Warplane shelling 139,Raed Ramadan ,Civilian,Adult - Male,Aleppo,Kafrahamreh,2015-12-07,Warplane shelling 140,Aamer Ramadan ,Civilian,Adult - Male,Aleppo,Kafrahamreh,2015-12-07,Warplane shelling 141,Mohammad Salem al-Mahmoud ,Civilian,Adult - Male,Aleppo,Kafrahamreh,2015-12-07,Warplane shelling 142,Yehya Qasemo ,Non-Civilian,Adult - Male,Hama,Al-Sermenieh,2015-12-07,Shooting 143,Hasan Ahmad al-Hardan ,Civilian,Adult - Male,Aleppo,Salheen,2015-12-07,Warplane shelling 144,Ayda al-Hasan ,Civilian,Adult - Female,Aleppo,Salheen,2015-12-07,Warplane shelling 145,Sahar Hamwi ,Civilian,Adult - Female,Aleppo,Salheen,2015-12-07,Warplane shelling 146,Abdul Hameed Sultan ,Civilian,Adult - Male,Aleppo,Hulluk,2015-12-07,Warplane shelling 147,Bilal Mahmoud ,Civilian,Child - Male,Aleppo,Hulluk,2015-12-07,Warplane shelling 148,Sahar Ghazal al-Hamwi ,Civilian,Adult - Female,Aleppo,Hulluk,2015-12-07,Warplane shelling 149,Fatme Ahmad al-Jasem ,Civilian,Adult - Female,Aleppo,Hulluk,2015-12-07,Warplane shelling 150,Unidentified ,Civilian,Child - Male,Aleppo,Hulluk,2015-12-07,Warplane shelling 151,Hasan Mohammad Rammo ,Civilian,Adult - Male,Aleppo,Sukkari neighborhood,2015-12-07,Warplane shelling 152,Hajar Mahmoud Akeel ,Civilian,Child - Female,Aleppo,Sukkari neighborhood,2015-12-07,Warplane shelling 153,Shaymaa Mahmoud Akeel ,Civilian,Child - Female,Aleppo,Sukkari neighborhood,2015-12-07,Warplane shelling 154,Abed Seyam ,Non-Civilian,Adult - Male,Damascus,Yarmuk Camp,2015-12-07,Warplane shelling 155,Unidentified ,Civilian,Adult - Male,Aleppo,,2015-12-07,Shelling 156,Abdul Rawof Mohammad ,Non-Civilian,Adult - Male,Aleppo,,2015-12-07,Shooting 157,Waleed Hamoush ,Non-Civilian,Adult - Male,Aleppo,,2015-12-07,Shooting 158,Abdulkareem al-Suleiman ,Non-Civilian,Adult - Male,Aleppo,,2015-12-07,Shooting 159,Mohammad al-Qarrat ,Non-Civilian,Adult - Male,Aleppo,,2015-12-07,Shooting 160,Abdullah al-Melhem al-Abdullah ,Non-Civilian,Adult - Male,Aleppo,,2015-12-07,Shooting 161,Yaser Saeed Ghanoum ,Non-Civilian,Adult - Male,Aleppo,,2015-12-07,Shooting 162,Ali Sultan al-Samouri ,Non-Civilian,Adult - Male,Daraa,Jamleh,2015-12-07,Kidnapping - Execution 163,Yousef Sultan al-Samouri ,Non-Civilian,Adult - Male,Daraa,Jamleh,2015-12-07,Kidnapping - Execution 164,Rami al-Sayo ,Non-Civilian,Adult - Male,Deir Ezzor,,2015-12-07,Kidnapping - Execution 165,Akram al-Merie ,Civilian,Adult - Male,Deir Ezzor,,2015-12-07,Kidnapping - Execution 166,Adnan Saleh al-Shaqran ,Non-Civilian,Adult - Male,Daraa,Fuqia,2015-12-07,Shooting 167,Alaa Wael Sadaqa ,Non-Civilian,Adult - Male,Daraa,Fuqia,2015-12-07,Shooting 168,Oqba Jad al-Kareem al-Hareeri ,Non-Civilian,Adult - Male,Daraa,Fuqia,2015-12-07,Shooting 169,Ali Abdul Ghani al-Shaqran ,Non-Civilian,Adult - Male,Daraa,Fuqia,2015-12-07,Shooting 170,Bushra Ahmad Adeel al-Hareeri ,Civilian,Adult - Female,Daraa,Bassr Al-Hareer,2015-12-07,Warplane shelling 171,Hsain Sami Shawar ,Civilian,Adult - Male,Idlib,Jisr Shagour: Najieh,2015-12-07,Warplane shelling 172,wife of Hsain Sami Shawar ,Civilian,Adult - Female,Idlib,Jisr Shagour: Najieh,2015-12-07,Warplane shelling
There are 15k+ lines of this and as you may notice some places have the same entries several times. My workflow was to get the data from the sqlite database into this big csv. After that i filtered doubled entries so I just got every place/province once. Therefore it was possible to decrease the query for the geocoder (I was so naive to think that you don't have a limit at all). My problem now is that I have two datasets which I can't put together again because simple "search and replace all entries" with the latitude/longitude information would be still a difficult and time-wasting task. Also because the entries numbers wouldn't match.I have two ideas and I for both of them I have no clue how to get there because I'm new to python and I was working all day on this data.
- Automate the process of search and replace (Province/Area) with (Province/Area,Latitude,Longitude)
Per incident I have several people who died at the same place on the same date. I could technically sum them up so the whole data woud become smaller (Where should I do this. In SQLite oder in Python with the csv). So i could query this data to the geocoder so I have a whole file again. Something like this where I would query the Province and the area to the geocoder:
rowid,Value_by_People,Status,Province,Area,Date_of_Death,Cause_of_Death 1,13,Civilian,Daraa,Sawara,2015-12-10,Warplane shelling 2,50,Civilian,Daraa,Sawara,2015-12-7,Shooting
Thank you for your ideas
EDIT1
query = ','.join(str(x) for x in (row['Country'],row['Province'],row['Area'])) errorquery = ','.join(str(x) for x in (row['Province'],row['Country'])) print(query) try: address, (latitude, longitude) = geolocator.geocode(query) except: address, (latitude, longitude) = geolocator.geocode(errorquery) #latitude = 'N/A' #longitude = 'N/A'
EDIT 3
I tried the changes but i cant get it working
import csv from geopy.geocoders import GoogleV3 geolocator = GoogleV3() #here some parameters are needed lookups = {} # declare this above the loop global tempquery global latitude, longitude def lookup_location(query, errorquery, lookups): tempquery = query try: address, (latitude, longitude) = lookups[query] except KeyError: # new lookup try: #address, (latitude, longitude) = geolocator.geocode(query) address, (latitude, longitude) = lookups[errorquery] except: # should probably try to catch specific exceptions #address = latitude = longitude = None try: address, (latitude, longitude) = geolocator.geocode(query) #address, (latitude, longitude) = lookups[errorquery] except KeyError: # new lookup try: address, (latitude, longitude) = geolocator.geocode(errorquery) tempquery = errorquery except: address = latitude = longitude = 'None' tempquery = errorquery lookups[tempquery] = address, (latitude, longitude) return address, latitude, longitude with open('151213_Martyrs_filtered_civilian_2015_with_country.csv', 'rb') as csvinput: with open('151213_locations_filtered_fiexedwith_cities_country.csv', 'w') as csvoutput: output_fieldnames = ['Name','Status','Sex','Country','Province','Area','Date_of_Death','Cause_of_Death','Latitude','Longitude'] writer = csv.DictWriter(csvoutput, delimiter=',', fieldnames=output_fieldnames) reader = csv.DictReader(csvinput) for row in reader: #here you have to replace the dict item by your csv column names query = ','.join(str(x) for x in (row['Country'],row['Province'],row['Area'])) errorquery = ','.join(str(x) for x in (row['Country'],row['Province'],row['Province'])) lookup_location(query, errorquery, lookups) output_row = {} output_row['Name'] = row['Name'] output_row['Status'] = row['Status'] output_row['Sex'] = row['Sex'] output_row['Country'] = row['Country'] output_row['Province'] = row['Province'] output_row['Area'] = row['Area'] output_row['Date_of_Death'] = row['Date_of_Death'] output_row['Cause_of_Death'] = row['Cause_of_Death'] output_row['Latitude'] = 0 output_row['Longitude'] = 0 writer.writerow(output_row)
With these errors
Traceback (most recent call last): File "geopy_script_04_changes.py", line 43, in <module> lookup_location(query, errorquery, lookups) File "geopy_script_04_changes.py", line 21, in lookup_location address, (latitude, longitude) = geolocator.geocode(query) TypeError: 'NoneType' object is not iterable
解决方案I changed the code a little bit so it worked for me. Thank you for your ideas and the help.
import csv from geopy.geocoders import GoogleV3 geolocator = GoogleV3() #here some parameters are needed lookups = {} with open('151213_Martyrs_filtered_civilian_2015_with_country.csv', 'rb') as csvinput: with open('151213_output_martyrs_final.csv', 'w') as csvoutput: output_fieldnames = ['Name','Status','Sex','Country','Province','Area','Date_of_Death','Cause_of_Death','Latitude','Longitude'] writer = csv.DictWriter(csvoutput, delimiter=',', fieldnames=output_fieldnames) reader = csv.DictReader(csvinput) for row in reader: if row['Province'].split(' ', 1) == 'Damascus': rowProv = "Damascus" else: rowProv = row['Province'] #here you have to replace the dict item by your csv column names query = ','.join(str(x) for x in (rowProv, row['Area'])) try: address, (latitude, longitude) = lookups[query] except KeyError: # new lookup try: query = ','.join(str(x) for x in (rowProv, rowProv)) address, (latitude, longitude) = lookups[query] print('lookup') except KeyError: # search try: query = ','.join(str(x) for x in (rowProv, row['Area'])) address, (latitude, longitude) = geolocator.geocode(query) except: # error query = ','.join(str(x) for x in (rowProv, rowProv)) address, (latitude, longitude) = geolocator.geocode(query) lookups[query] = address, (latitude, longitude) print(query) #here is the writing section output_row = {} output_row['Name'] = row['Name'] output_row['Status'] = row['Status'] output_row['Sex'] = row['Sex'] output_row['Country'] = row['Country'] output_row['Province'] = row['Province'] output_row['Area'] = row['Area'] output_row['Date_of_Death'] = row['Date_of_Death'] output_row['Cause_of_Death'] = row['Cause_of_Death'] output_row['Latitude'] = latitude output_row['Longitude'] = longitude writer.writerow(output_row)
这篇关于使用Geopy和大数据进行地理编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!