data/process_data.py
def clean_data(df):
    """
    Clean data and create categories Columns.

    :param df: Pandas Dataframe. Dataframe Input
    :return: Pandas Dataframe. Dataframe cleaned with categories at your own column
    """

    # create a dataframe of the 36 individual category columns
    categories = df['categories'].str.split(';', expand=True)

    # Extract a list of new column names for categories.
    category_colnames = df['categories'].values[0].replace('-1', '').replace('-0', '').split(';')

    # rename the columns of `categories`
    categories.columns = category_colnames

    for column in categories:
        categories[column] = categories[column].apply(lambda x: x[-1])

        # convert column from string to numeric
        categories[column] = categories[column].astype(int)

        # checking for values other than 0 and 1 and converting number > 1 to 1
        if len(categories[column].unique()) > 2:
            categories[column] = categories[column].map(lambda x: 1 if x == 2 else x)

    # drop the original categories column from `df`
    df.drop('categories', axis=1, inplace=True)

    # concatenate the original dataframe with the new `categories` dataframe
    df = pd.concat([df, categories], axis=1)

    # drop duplicates
    df.drop_duplicates(inplace=True)

    return df

    Clean data and create categories Columns.

    :param df: Pandas Dataframe. Dataframe Input
    :return: Pandas Dataframe. Dataframe cleaned with categories at your own column
    
Clean data and create categories Columns.
Clean data and create categories Columns .
def clean_data(df):
    categories = df['categories'].str.split(';', expand=True)
    category_colnames = df['categories'].values[0].replace('-1', '').replace('-0', '').split(';')
    categories.columns = category_colnames
    for column in categories:
        categories[column] = categories[column].apply(lambda x: x[-1])
        categories[column] = categories[column].astype(int)
        if len(categories[column].unique()) > 2:
            categories[column] = categories[column].map(lambda x: 1 if x == 2 else x)
    df.drop('categories', axis=1, inplace=True)
    df = pd.concat([df, categories], axis=1)
    df.drop_duplicates(inplace=True)
    return df
def clean_data ( df ) : categories = df [ 'categories' ] . str . split ( ';' , expand = True ) category_colnames = df [ 'categories' ] . values [ 0 ] . replace ( '-1' , '' ) . replace ( '-0' , '' ) . split ( ';' ) categories . columns = category_colnames for column in categories : categories [ column ] = categories [ column ] . apply ( lambda x : x [ - 1 ] ) categories [ column ] = categories [ column ] . astype ( int ) if len ( categories [ column ] . unique ( ) ) > 2 : categories [ column ] = categories [ column ] . map ( lambda x : 1 if x == 2 else x ) df . drop ( 'categories' , axis = 1 , inplace = True ) df = pd . concat ( [ df , categories ] , axis = 1 ) df . drop_duplicates ( inplace = True ) return df
Clean data and create categories Columns.
Clean data and create categories Columns .
"""
    Clean data and create categories Columns.

    :param df: Pandas Dataframe. Dataframe Input
    :return: Pandas Dataframe. Dataframe cleaned with categories at your own column
    """ # create a dataframe of the 36 individual category columns # Extract a list of new column names for categories. # rename the columns of `categories` # convert column from string to numeric # checking for values other than 0 and 1 and converting number > 1 to 1 # drop the original categories column from `df` # concatenate the original dataframe with the new `categories` dataframe # drop duplicates
Pandas Dataframe. Dataframe cleaned with categories at your own column
Pandas Dataframe . Dataframe cleaned with categories at your own column
df
Pandas Dataframe. Dataframe Input
Pandas Dataframe . Dataframe Input