data/process_data.py
def clean_data(dataset):
    """The clean_data function will return a clean DataFrame after removing,
        replacing and cleaning the DataFrame to  a suitable form for further
        saving to database for analysis

    Args:
        dataset (DataFrame): the DataFrame for data wrangling

    Returns:
        DataFrame: The DataFrame for saving to database and later analysis

    """
    # Split the values in the categories column on the ; character so that
    # each value becomes a separate column
    cat = dataset.categories.str.split(";", expand=True)

    # Use the first row of categories dataframe to create column names for the
    # categories data.
    row = cat.iloc[0]
    category_colnames = row.apply(lambda x: x[:-2])
    cat.columns = category_colnames

    # extract only the digits in categories columns
    for column in cat:
        # set each value to be the last character of the string
        cat[column] = cat[column].str[-1:]

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

    # drop the original categories column from dataset
    dataset.drop(columns=["categories"], inplace=True)

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

    # drop duplicates and columns not essential for further analysis
    df_.drop_duplicates(keep="first", inplace=True)

    # drop columns not needed
    df_.drop(columns=["id", "original"], inplace=True)

    return df_
The clean_data function will return a clean DataFrame after removing,
        replacing and cleaning the DataFrame to  a suitable form for further
        saving to database for analysis

    Args:
        dataset (DataFrame): the DataFrame for data wrangling

    Returns:
        DataFrame: The DataFrame for saving to database and later analysis

    
The clean_data function will return a clean DataFrame after removing,
replacing and cleaning the DataFrame to  a suitable form for further
saving to database for analysis
The clean_data function will return a clean DataFrame after removing replacing and cleaning the DataFrame to a suitable form for further saving to database for analysis
def clean_data(dataset):
    cat = dataset.categories.str.split(";", expand=True)
    row = cat.iloc[0]
    category_colnames = row.apply(lambda x: x[:-2])
    cat.columns = category_colnames
    for column in cat:
        cat[column] = cat[column].str[-1:]
        cat[column] = cat[column].astype(int)
    dataset.drop(columns=["categories"], inplace=True)
    df_ = pd.concat([dataset, cat], axis=1)
    df_.drop_duplicates(keep="first", inplace=True)
    df_.drop(columns=["id", "original"], inplace=True)
    return df_
def clean_data ( dataset ) : cat = dataset . categories . str . split ( ";" , expand = True ) row = cat . iloc [ 0 ] category_colnames = row . apply ( lambda x : x [ : - 2 ] ) cat . columns = category_colnames for column in cat : cat [ column ] = cat [ column ] . str [ - 1 : ] cat [ column ] = cat [ column ] . astype ( int ) dataset . drop ( columns = [ "categories" ] , inplace = True ) df_ = pd . concat ( [ dataset , cat ] , axis = 1 ) df_ . drop_duplicates ( keep = "first" , inplace = True ) df_ . drop ( columns = [ "id" , "original" ] , inplace = True ) return df_
The clean_data function will return a clean DataFrame after removing,
replacing and cleaning the DataFrame to  a suitable form for further
saving to database for analysis
The clean_data function will return a clean DataFrame after removing replacing and cleaning the DataFrame to a suitable form for further saving to database for analysis
"""The clean_data function will return a clean DataFrame after removing,
        replacing and cleaning the DataFrame to  a suitable form for further
        saving to database for analysis

    Args:
        dataset (DataFrame): the DataFrame for data wrangling

    Returns:
        DataFrame: The DataFrame for saving to database and later analysis

    """ # Split the values in the categories column on the ; character so that # each value becomes a separate column # Use the first row of categories dataframe to create column names for the # categories data. # extract only the digits in categories columns # set each value to be the last character of the string # convert column from string to numeric # drop the original categories column from dataset # concatenate the original dataframe with the new `categories` # dataframe # drop duplicates and columns not essential for further analysis # drop columns not needed
The DataFrame for saving to database and later analysis
The DataFrame for saving to database and later analysis
DataFrame
dataset
the DataFrame for data wrangling
the DataFrame for data wrangling