Code/5-data-cleansing/clean_met.py
def clean_gender(data):
    """
    Clean Artist Gender column using Regex
    """
    column_info(data, "Artist Gender")

    # Assign Unknowk to all null values
    data["ArtistGenderClean"] = data["Artist Gender"].fillna("Unknown")

    # Clean up Pipes
    pattern_pipes = "\|+"
    pattern_pipes_regex = re.compile(pattern_pipes)
    cadena_reemplazo = ""
    data["ArtistGenderClean"] = data["ArtistGenderClean"].apply(
        lambda x: pattern_pipes_regex.sub(cadena_reemplazo, x))
    data["ArtistGenderClean"].value_counts()

    # replace multiple instances of Female by one Female
    pattern_female = "(Female)+"
    pattern_female_regex = re.compile(pattern_female)
    cadena_reemplazo = "Female"
    data["ArtistGenderClean"] = data["ArtistGenderClean"].apply(
        lambda x: pattern_female_regex.sub(cadena_reemplazo, x))
    data["ArtistGenderClean"].value_counts()

    # replace empty values by Male
    empty_mask = data["ArtistGenderClean"] == ""
    data.loc[empty_mask, "ArtistGenderClean"] = "Male"
    data["ArtistGenderClean"].value_counts()

    column_info(data, "ArtistGenderClean")

    Clean Artist Gender column using Regex
    
Clean Artist Gender column using Regex
Clean Artist Gender column using Regex
def clean_gender(data):
    column_info(data, "Artist Gender")
    data["ArtistGenderClean"] = data["Artist Gender"].fillna("Unknown")
    pattern_pipes = "\|+"
    pattern_pipes_regex = re.compile(pattern_pipes)
    cadena_reemplazo = ""
    data["ArtistGenderClean"] = data["ArtistGenderClean"].apply(
        lambda x: pattern_pipes_regex.sub(cadena_reemplazo, x))
    data["ArtistGenderClean"].value_counts()
    pattern_female = "(Female)+"
    pattern_female_regex = re.compile(pattern_female)
    cadena_reemplazo = "Female"
    data["ArtistGenderClean"] = data["ArtistGenderClean"].apply(
        lambda x: pattern_female_regex.sub(cadena_reemplazo, x))
    data["ArtistGenderClean"].value_counts()
    empty_mask = data["ArtistGenderClean"] == ""
    data.loc[empty_mask, "ArtistGenderClean"] = "Male"
    data["ArtistGenderClean"].value_counts()
    column_info(data, "ArtistGenderClean")
def clean_gender ( data ) : column_info ( data , "Artist Gender" ) data [ "ArtistGenderClean" ] = data [ "Artist Gender" ] . fillna ( "Unknown" ) pattern_pipes = "\|+" pattern_pipes_regex = re . compile ( pattern_pipes ) cadena_reemplazo = "" data [ "ArtistGenderClean" ] = data [ "ArtistGenderClean" ] . apply ( lambda x : pattern_pipes_regex . sub ( cadena_reemplazo , x ) ) data [ "ArtistGenderClean" ] . value_counts ( ) pattern_female = "(Female)+" pattern_female_regex = re . compile ( pattern_female ) cadena_reemplazo = "Female" data [ "ArtistGenderClean" ] = data [ "ArtistGenderClean" ] . apply ( lambda x : pattern_female_regex . sub ( cadena_reemplazo , x ) ) data [ "ArtistGenderClean" ] . value_counts ( ) empty_mask = data [ "ArtistGenderClean" ] == "" data . loc [ empty_mask , "ArtistGenderClean" ] = "Male" data [ "ArtistGenderClean" ] . value_counts ( ) column_info ( data , "ArtistGenderClean" )
Clean Artist Gender column using Regex
Clean Artist Gender column using Regex
"""
    Clean Artist Gender column using Regex
    """ # Assign Unknowk to all null values # Clean up Pipes # replace multiple instances of Female by one Female # replace empty values by Male
data