application_vnd.jupyter.stderr_output_2.png text_plain_output_1.png
from tqdm.auto import tqdm

import numpy as np

import pandas as pd

countries_only = pd.read_json('../input/precise-location/countries.json')
country_ex = pd.read_csv('../input/precise-location/country_iso_codes_expanded.csv')
country_ex = country_ex.fillna(' ')
contriesSet = []
for i in tqdm(range(len(countries_only))):
    contriesSet.append(countries_only['name'][i])
    contriesSet += list(countries_only['translations'][i].values())
    contriesSet = list(set(contriesSet))
dictMultiLangCountry = {}
for i in tqdm(range(len(countries_only))):
    dictMultiLangCountry[countries_only['name'][i]] = countries_only['name'][i]
    mc = list(countries_only['translations'][i].values())
    for c in mc:
        dictMultiLangCountry[c] = countries_only['name'][i]
for i in tqdm(range(len(country_ex))):
    for col in range(26):
        if country_ex[f'alternative_country_name_{col}'][i] != ' ':
            dictMultiLangCountry[country_ex[f'alternative_country_name_{col}'][i]] = country_ex['country'][i]
dictMultiLangCountry['China'] = 'China'
dictMultiLangCountry['SIngapore'] = 'Singapore'
dictMultiLangCountry.pop('')

geoname_cities = pd.read_csv('../input/precise-location/geonames-all-cities-with-a-population-1000.csv', sep=';')
dictAllUnicodeCities = dict()
for i in tqdm(range(len(geoname_cities))):
    if geoname_cities.Name[i] in dictAllUnicodeCities:
        dictAllUnicodeCities[geoname_cities.Name[i]].append(geoname_cities['Country name EN'][i])
        dictAllUnicodeCities[geoname_cities.Name[i]] = list(set(dictAllUnicodeCities[geoname_cities.Name[i]]))
    else:
        dictAllUnicodeCities[geoname_cities.Name[i]] = [geoname_cities['Country name EN'][i]]
    if geoname_cities['Alternate Names'][i] is not np.NaN:
        alt_ = geoname_cities['Alternate Names'][i].split(',')
        for city in alt_:
            if city in dictAllUnicodeCities:
                dictAllUnicodeCities[city].append(geoname_cities['Country name EN'][i])
                dictAllUnicodeCities[city] = list(set(dictAllUnicodeCities[city]))
            else:
                dictAllUnicodeCities[city] = [geoname_cities['Country name EN'][i]]
dictAllUnicodeCities['Dhaka'] = ['Bangladesh']
dictAllUnicodeCities['Changi'] = ['Singapore']
dictAllUnicodeCities['Admiralty'] = ['Singapore']
dictAllUnicodeCities['North Bridge'] = ['Singapore']
dictAllUnicodeCities['Greater Bay'] = ['China']
dictAllUnicodeCities['Philadelphia'] = ['United States']
dictAllUnicodeCities['Manila'] = ['Philippines']
dictAllUnicodeCities['Irving'] = ['Singapore']
dictAllUnicodeCities['HDB Hub'] = ['Singapore']
dictAllUnicodeCities['s Heerenberg'] = ['Netherlands']
dictAllUnicodeCities['S Heerenberg'] = ['Netherlands']
dictAllUnicodeCities['Durham'] = ['United States']
dictAllUnicodeCities['dhabi'] = ['United Arab Emirates']
dictAllUnicodeCities['Scotland'] = ['United Kingdom']
dictAllUnicodeCities['Middle East'] = ['United Arab Emirates']
dictAllUnicodeCities['Alberta'] = ['Canada']
dictAllUnicodeCities['Colombo'] = ['Sri Lanka']
dictAllUnicodeCities['Phoenix'] = ['United States']
dictAllUnicodeCities.pop('Ahmad')
dictAllUnicodeCities.pop('Road')
dictAllUnicodeCities.pop('Street')
dictAllUnicodeCities.pop('30')
dictAllUnicodeCities.pop('North')
dictAllUnicodeCities.pop('West')
dictAllUnicodeCities.pop('Bridge')
dictAllUnicodeCities.pop('Model')
dictAllUnicodeCities.pop('Spa')
dictAllUnicodeCities.pop('Park')
dictAllUnicodeCities.pop('Bay')
dictAllUnicodeCities.pop('Home')
dictAllUnicodeCities.pop('List')
dictAllUnicodeCities.pop('China')
dictAllUnicodeCities.pop('Court')
dictAllUnicodeCities.pop('Wing')
dictAllUnicodeCities.pop('HDB')
dictAllUnicodeCities.pop('Al')
dictAllUnicodeCities.pop('Bin')
dictAllUnicodeCities.pop('A')
dictAllUnicodeCities.pop('Vista')
dictAllUnicodeCities.pop('Aria')
dictAllUnicodeCities.pop('No')
dictAllUnicodeCities.pop('I')