-
Notifications
You must be signed in to change notification settings - Fork 25
/
Splttype2CountryConverter.py
28 lines (23 loc) · 1.14 KB
/
Splttype2CountryConverter.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
import pycountry
class Splttype2CountryConverter:
@staticmethod
def convertSplttype2Country(dataFrame_SPLTTYPE_By_VAERS_ID):
dataFrame_COUNTRY_By_VAERS_ID = dataFrame_SPLTTYPE_By_VAERS_ID[['SPLTTYPE']].copy()
dataFrame_COUNTRY_By_VAERS_ID['COUNTRY'] = Splttype2CountryConverter._splttype2Country(dataFrame_COUNTRY_By_VAERS_ID['SPLTTYPE'])
dataFrame_COUNTRY_By_VAERS_ID = dataFrame_COUNTRY_By_VAERS_ID.drop(columns = ['SPLTTYPE'])
return dataFrame_COUNTRY_By_VAERS_ID
@staticmethod
def _splttype2Country(splttypeSeries):
return (splttypeSeries
.apply(
lambda splttype:
Splttype2CountryConverter._getCountryNameOfSplttypeOrDefault(
splttype = splttype,
default = None))
.astype("string"))
@staticmethod
def _getCountryNameOfSplttypeOrDefault(splttype, default):
if not isinstance(splttype, str):
return default
country = pycountry.countries.get(alpha_2 = splttype[:2])
return country.name if country is not None else default