Commit f102f9d3 by chenyuanjie

etsy版本country字段处理脏数据

parent 4fcfd8ec
...@@ -55,12 +55,13 @@ NO_VALUES = ['no', 'n', 'false', '0', '否'] ...@@ -55,12 +55,13 @@ NO_VALUES = ['no', 'n', 'false', '0', '否']
def country_to_cn(col_name): def country_to_cn(col_name):
"""国家统一为中文,空串/[] 置空,字典未命中保留原值""" """国家统一为中文:先去掉 [] 和引号(如 ['United States']),空值置空,字典未命中保留清洗后的值"""
country_map = F.create_map([F.lit(x) for x in chain(*COUNTRY_MAP.items())]) country_map = F.create_map([F.lit(x) for x in chain(*COUNTRY_MAP.items())])
country_key = F.lower(F.trim(F.col(col_name))) country_clean = F.trim(F.regexp_replace(F.col(col_name), r"[\[\]'\"]", ''))
country_key = F.lower(country_clean)
return F.when( return F.when(
country_key.isNull() | country_key.isin('', '[]'), F.lit(None) country_key.isNull() | (country_key == ''), F.lit(None)
).otherwise(F.coalesce(country_map[country_key], F.trim(F.col(col_name)))) ).otherwise(F.coalesce(country_map[country_key], country_clean))
def yes_no_to_cn(col_name): def yes_no_to_cn(col_name):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment