-
Notifications
You must be signed in to change notification settings - Fork 0
/
CountryCode.py
42 lines (31 loc) · 1.04 KB
/
CountryCode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pandas as pd
df = pd.read_csv(r'/Users/omkarshanbhag/Desktop/Pierce_final.csv', encoding = 'latin-1')
df_1 = pd.read_csv(r'/Users/omkarshanbhag/Desktop/iso_3166_2_countries.csv', encoding = 'latin-1')
country_list_prelim = df['Country'].tolist()
chicken = df['Occupation'].tolist()
other_chicken = df['Geolocation'].tolist()
other_chicken = df['Author'].tolist()
country_list = []
for country in country_list_prelim:
if country == 'Australien':
country_list.append('Australia')
else:
country_list.append(country)
country_comp = df_1['Common Name'].tolist()
letter_code = df_1['ISO 3166-1 2 Letter Code'].tolist()
final_code_list = []
index_list = []
y = 0
for country in country_list:
x = 0
for c in country_comp:
if c == country:
final_code_list.append(letter_code[x])
index_list.append(y)
x += 1
y += 1
while len(final_code_list) < len(chicken):
final_code_list.append(0)
ne = pd.Series(final_code_list)
df['Country Code'] = ne.values
df.to_csv('Final_input.csv')