Package : Transform : ISO 3166 Class - waidyanatha/dongcha GitHub Wiki
from dongcha.modules.etl.transform import isoAlphaCodes as iso
Introduction
The transformation package offers functions to find and reverse engineer ISO 3166 country and subdivision codes.
Functions
Get ISO Country Codes
Augments columns with the requested ISO codes.
get_iso_3166(
data : any, # any dataset that can be transformed into pyspark DataFrame
t_iso: dict, # dictionary defining the transformation
)
- The input dataset must be one that can be converted to a pyspark DataFrame
- The Transformation dictionary must indicate
- whether it is COUNTRY (3166-1) or SUBDIV (3166-2) transformation
- specify the attribute name key: ATTRNAME along with the column name
- indicate the the requested TRANSFORMATION with a dictionary; where the key: ALPHA2, ALPHA2, UN, CODE is the transformation and the value is the return results column name
- Example:
t_iso={
"COUNTRY": {
"ATTRNAME" : 'the_country',
"TRANSFORM" : {
"ALPHA2" : 'country_3166_alpha2',
"ALPHA3" : 'country_3166_alpha3',
"UN" : 'country_un_code'
}
},
}
- Return the results in the columns (if specified, else in default columns)
the_country | country_3661_alpha2 | country_3661_alpha3 | country_un_code
Egypt | EG | EGY | 818