data/process_data.py
def clean_data(df):
    """
    Clean data from dataframe
        - split categories into separated clearly named columns
        - convert to binary
        - drop duplicates

    Parameters:
    df (pandas dataframe): the dataframe to be clean

    Returns:
    df (pandas dataframe): a cleaned dataframe
    """
    
    categories =  df.categories.str.split(';', expand=True)

    row = categories.iloc[0]
    category_colnames = [r.split('-')[0] for r in row]
    categories.columns = category_colnames

    for column in categories:
        # set each value to be the last character of the string
        categories[column] = categories[column].apply(lambda x: str(x)[-1])
        
        # convert column from string to numeric
        categories[column] = categories[column].astype(int)

    df.drop(['categories'], axis=1, inplace=True)

    df = pd.concat([df, categories], axis=1)
    df.drop_duplicates(inplace=True)


    #Transform values in binary
    df['related'] = df['related'].astype('str').str.replace('2', '1')
    df['related'] = df['related'].astype('int')
    
    return df

    Clean data from dataframe
        - split categories into separated clearly named columns
        - convert to binary
        - drop duplicates

    Parameters:
    df (pandas dataframe): the dataframe to be clean

    Returns:
    df (pandas dataframe): a cleaned dataframe
    
Clean data from dataframe
split categories into separated clearly named columns
convert to binary
drop duplicates

df (pandas dataframe): the dataframe to be clean

df (pandas dataframe): a cleaned dataframe
Clean data from dataframe split categories into separated clearly named columns convert to binary drop duplicates df ( pandas dataframe ) : the dataframe to be clean df ( pandas dataframe ) : a cleaned dataframe
def clean_data(df):
    categories =  df.categories.str.split(';', expand=True)
    row = categories.iloc[0]
    category_colnames = [r.split('-')[0] for r in row]
    categories.columns = category_colnames
    for column in categories:
        categories[column] = categories[column].apply(lambda x: str(x)[-1])
        categories[column] = categories[column].astype(int)
    df.drop(['categories'], axis=1, inplace=True)
    df = pd.concat([df, categories], axis=1)
    df.drop_duplicates(inplace=True)
    df['related'] = df['related'].astype('str').str.replace('2', '1')
    df['related'] = df['related'].astype('int')
    return df
def clean_data ( df ) : categories = df . categories . str . split ( ';' , expand = True ) row = categories . iloc [ 0 ] category_colnames = [ r . split ( '-' ) [ 0 ] for r in row ] categories . columns = category_colnames for column in categories : categories [ column ] = categories [ column ] . apply ( lambda x : str ( x ) [ - 1 ] ) categories [ column ] = categories [ column ] . astype ( int ) df . drop ( [ 'categories' ] , axis = 1 , inplace = True ) df = pd . concat ( [ df , categories ] , axis = 1 ) df . drop_duplicates ( inplace = True ) df [ 'related' ] = df [ 'related' ] . astype ( 'str' ) . str . replace ( '2' , '1' ) df [ 'related' ] = df [ 'related' ] . astype ( 'int' ) return df
Clean data from dataframe
 split categories into separated clearly named columns
 convert to binary
 drop duplicates
Clean data from dataframe split categories into separated clearly named columns convert to binary drop duplicates
"""
    Clean data from dataframe
        - split categories into separated clearly named columns
        - convert to binary
        - drop duplicates

    Parameters:
    df (pandas dataframe): the dataframe to be clean

    Returns:
    df (pandas dataframe): a cleaned dataframe
    """ # set each value to be the last character of the string # convert column from string to numeric #Transform values in binary
df