preprocessing.py
def create_features(df):
    '''
    Creates features based on the original dataframe. Converts track duration into new columns for length in seconds and
    length in minutes. Creates a feature for a boolean value if the track features an artist or not. Lower cases all 
    characters in text data columns. Returns the df with these features created at the end and string conversions.
    '''

    # Feature Engineering
    # converting track length from ms to seconds as new column
    df['duration_seconds'] = df.duration_ms / 1_000
    # converting track length from seconds to minutes as new column
    df['duration_minutes'] = df.duration_seconds / 60
    # creating boolean if track has a featured artist
    df['is_featured_artist'] = df.track_name.str.contains('feat').astype('int')

    # Lowercasing String
    # using string function to convert all characters to lowercase
    df['artist'] = df.artist.str.lower()
    df['album'] = df.album.str.lower()
    df['track_name'] = df.track_name.str.lower()

    # Create Seperate Columns for Year, Month, and Day
    # creating dataframe of release day split by '-'
    dates = df.release_date.str.split('-', expand=True)
    # renaming columns to respective year, month, and day
    dates.columns = ['release_year','release_month','release_day']
    # ensuring index is the same as the df
    dates.index = df.index
    # adding to the dataframe with axis=1 to add column-wise
    df = pd.concat([dates, df], axis=1)

    # Flatten column MultiIndex
    #df.columns = [x[0] for x in df.columns]

    df.release_year = df.release_year.astype('int')

    # bins set edge points for range of label
    # goes from 1980-1989, 1990-1999, 2000-2009, 2019-2019, 2020-2029
    df['decade'] = pd.cut(x=df.release_year, bins=[1979,1989,1999,2009,2019,2029], 
                                                labels=['80s','90s','2000s','2010s','2020s'])

    # create is_top_billboard_label
    top_ten_billboard = ['Def Jam', 'Young Money', 'Roc-A-Fella', 'Jive', 'Bad Boy', 'Grand Hustle', 'Shady', 'Ruffhouse', 'Cash Money', 'Columbia']
    pattern = '|'.join(top_ten_billboard)
    df['is_top_billboard_label'] = df.label.str.contains(pattern)
    df['is_top_billboard_label'] = df.is_top_billboard_label.astype('int')

    return df

    Creates features based on the original dataframe. Converts track duration into new columns for length in seconds and
    length in minutes. Creates a feature for a boolean value if the track features an artist or not. Lower cases all 
    characters in text data columns. Returns the df with these features created at the end and string conversions.
    
Creates features based on the original dataframe. Converts track duration into new columns for length in seconds and
length in minutes. Creates a feature for a boolean value if the track features an artist or not. Lower cases all
characters in text data columns. Returns the df with these features created at the end and string conversions.
Creates features based on the original dataframe . Converts track duration into new columns for length in seconds and length in minutes . Creates a feature for a boolean value if the track features an artist or not . Lower cases all characters in text data columns . Returns the df with these features created at the end and string conversions .
def create_features(df):
    df['duration_seconds'] = df.duration_ms / 1_000
    df['duration_minutes'] = df.duration_seconds / 60
    df['is_featured_artist'] = df.track_name.str.contains('feat').astype('int')
    df['artist'] = df.artist.str.lower()
    df['album'] = df.album.str.lower()
    df['track_name'] = df.track_name.str.lower()
    dates = df.release_date.str.split('-', expand=True)
    dates.columns = ['release_year','release_month','release_day']
    dates.index = df.index
    df = pd.concat([dates, df], axis=1)
    df.release_year = df.release_year.astype('int')
    df['decade'] = pd.cut(x=df.release_year, bins=[1979,1989,1999,2009,2019,2029], 
                                                labels=['80s','90s','2000s','2010s','2020s'])
    top_ten_billboard = ['Def Jam', 'Young Money', 'Roc-A-Fella', 'Jive', 'Bad Boy', 'Grand Hustle', 'Shady', 'Ruffhouse', 'Cash Money', 'Columbia']
    pattern = '|'.join(top_ten_billboard)
    df['is_top_billboard_label'] = df.label.str.contains(pattern)
    df['is_top_billboard_label'] = df.is_top_billboard_label.astype('int')
    return df
def create_features ( df ) : df [ 'duration_seconds' ] = df . duration_ms / 1_000 df [ 'duration_minutes' ] = df . duration_seconds / 60 df [ 'is_featured_artist' ] = df . track_name . str . contains ( 'feat' ) . astype ( 'int' ) df [ 'artist' ] = df . artist . str . lower ( ) df [ 'album' ] = df . album . str . lower ( ) df [ 'track_name' ] = df . track_name . str . lower ( ) dates = df . release_date . str . split ( '-' , expand = True ) dates . columns = [ 'release_year' , 'release_month' , 'release_day' ] dates . index = df . index df = pd . concat ( [ dates , df ] , axis = 1 ) df . release_year = df . release_year . astype ( 'int' ) df [ 'decade' ] = pd . cut ( x = df . release_year , bins = [ 1979 , 1989 , 1999 , 2009 , 2019 , 2029 ] , labels = [ '80s' , '90s' , '2000s' , '2010s' , '2020s' ] ) top_ten_billboard = [ 'Def Jam' , 'Young Money' , 'Roc-A-Fella' , 'Jive' , 'Bad Boy' , 'Grand Hustle' , 'Shady' , 'Ruffhouse' , 'Cash Money' , 'Columbia' ] pattern = '|' . join ( top_ten_billboard ) df [ 'is_top_billboard_label' ] = df . label . str . contains ( pattern ) df [ 'is_top_billboard_label' ] = df . is_top_billboard_label . astype ( 'int' ) return df
Creates features based on the original dataframe.
Creates features based on the original dataframe .
'''
    Creates features based on the original dataframe. Converts track duration into new columns for length in seconds and
    length in minutes. Creates a feature for a boolean value if the track features an artist or not. Lower cases all 
    characters in text data columns. Returns the df with these features created at the end and string conversions.
    ''' # Feature Engineering # converting track length from ms to seconds as new column # converting track length from seconds to minutes as new column # creating boolean if track has a featured artist # Lowercasing String # using string function to convert all characters to lowercase # Create Seperate Columns for Year, Month, and Day # creating dataframe of release day split by '-' # renaming columns to respective year, month, and day # ensuring index is the same as the df # adding to the dataframe with axis=1 to add column-wise # Flatten column MultiIndex #df.columns = [x[0] for x in df.columns] # bins set edge points for range of label # goes from 1980-1989, 1990-1999, 2000-2009, 2019-2019, 2020-2029 # create is_top_billboard_label
df