src/03_modelling/07_feature_engineering.py
def history(df):
        """This function assigns a binary variable
            to each business id:
            if the business has been operating for
            more than 5 years, it will be assigned
            an 1, otherwise 0.
        """

        df['history'] = np.zeros(len(df))

        for i in df.business_id.unique():
            id_hist = len(df[df.business_id == i])

            if id_hist >= 5:
                history = [0]*5+[1]*(id_hist-5)
                df.loc[df.business_id == i,
                       'history'] = history

        return df
This function assigns a binary variable
            to each business id:
            if the business has been operating for
            more than 5 years, it will be assigned
            an 1, otherwise 0.
        
This function assigns a binary variable
to each business id:
if the business has been operating for
more than 5 years, it will be assigned
an 1, otherwise 0.
This function assigns a binary variable to each business id : if the business has been operating for more than 5 years it will be assigned an 1 otherwise 0 .
def history(df):
        df['history'] = np.zeros(len(df))
        for i in df.business_id.unique():
            id_hist = len(df[df.business_id == i])
            if id_hist >= 5:
                history = [0]*5+[1]*(id_hist-5)
                df.loc[df.business_id == i,
                       'history'] = history
        return df
def history ( df ) : df [ 'history' ] = np . zeros ( len ( df ) ) for i in df . business_id . unique ( ) : id_hist = len ( df [ df . business_id == i ] ) if id_hist >= 5 : history = [ 0 ] * 5 + [ 1 ] * ( id_hist - 5 ) df . loc [ df . business_id == i , 'history' ] = history return df
This function assigns a binary variable
to each business id:
if the business has been operating for
more than 5 years, it will be assigned
an 1, otherwise 0.
This function assigns a binary variable to each business id : if the business has been operating for more than 5 years it will be assigned an 1 otherwise 0 .
"""This function assigns a binary variable
            to each business id:
            if the business has been operating for
            more than 5 years, it will be assigned
            an 1, otherwise 0.
        """
df