Code/5-data-cleansing/clean_met.py
def clean_year(data):
    """
    Clean Accession Year column using Regex
    """
    column_info(data, "AccessionYear")

    pattern_fecha = "(?P<year>\d\d\d\d)(?P<month_day>\-\d\d\-\d\d)*"
    pattern_fecha_regex = re.compile(pattern_fecha)
    # resultado_fechas = data.AccessionYear.apply(lambda x: x if (x is np.NaN) | (x is None) else pattern_fecha_regex.match(x))
    resultado_fechas = data.AccessionYear.apply(lambda x: x if x is np.NaN else
                                                pattern_fecha_regex.match(x))

    year_match = resultado_fechas.apply(lambda x: x
                                        if x is np.NaN else x.group("year"))
    logging.info(year_match.dtype)

    year_match_fill = year_match.fillna(0)
    year_match_fill_numeric = year_match_fill.astype(int)

    data["AccessionYearClean"] = year_match_fill_numeric
    data.dtypes

    column_info(data, "AccessionYearClean")
    return data

    Clean Accession Year column using Regex
    
Clean Accession Year column using Regex
Clean Accession Year column using Regex
def clean_year(data):
    column_info(data, "AccessionYear")
    pattern_fecha = "(?P<year>\d\d\d\d)(?P<month_day>\-\d\d\-\d\d)*"
    pattern_fecha_regex = re.compile(pattern_fecha)
    resultado_fechas = data.AccessionYear.apply(lambda x: x if x is np.NaN else
                                                pattern_fecha_regex.match(x))
    year_match = resultado_fechas.apply(lambda x: x
                                        if x is np.NaN else x.group("year"))
    logging.info(year_match.dtype)
    year_match_fill = year_match.fillna(0)
    year_match_fill_numeric = year_match_fill.astype(int)
    data["AccessionYearClean"] = year_match_fill_numeric
    data.dtypes
    column_info(data, "AccessionYearClean")
    return data
def clean_year ( data ) : column_info ( data , "AccessionYear" ) pattern_fecha = "(?P<year>\d\d\d\d)(?P<month_day>\-\d\d\-\d\d)*" pattern_fecha_regex = re . compile ( pattern_fecha ) resultado_fechas = data . AccessionYear . apply ( lambda x : x if x is np . NaN else pattern_fecha_regex . match ( x ) ) year_match = resultado_fechas . apply ( lambda x : x if x is np . NaN else x . group ( "year" ) ) logging . info ( year_match . dtype ) year_match_fill = year_match . fillna ( 0 ) year_match_fill_numeric = year_match_fill . astype ( int ) data [ "AccessionYearClean" ] = year_match_fill_numeric data . dtypes column_info ( data , "AccessionYearClean" ) return data
Clean Accession Year column using Regex
Clean Accession Year column using Regex
"""
    Clean Accession Year column using Regex
    """ # resultado_fechas = data.AccessionYear.apply(lambda x: x if (x is np.NaN) | (x is None) else pattern_fecha_regex.match(x))
data