<jupyter_start><jupyter_text>IMPORTS  Libraries<jupyter_code>import pandas as pd
import numpy as np

import warnings
warnings.filterwarnings("ignore")

import datetime<jupyter_output><empty_output><jupyter_text>Loading Data<jupyter_code>dfRaw = pd.read_csv('../../01-Data/Results/01-FirstRoundCRISP/dfDescriptionData.csv', low_memory=False, parse_dates=['Date'])<jupyter_output><empty_output><jupyter_text>FEATURE ENGINEERING<jupyter_code>dfRaw1 = dfRaw.copy()
#year
dfRaw1['Year'] = dfRaw1['Date'].dt.year

#month
dfRaw1['Month'] = dfRaw1['Date'].dt.month

#day
dfRaw1['Day'] = dfRaw1['Date'].dt.day

#week of year
dfRaw1['WeekOfYear'] = dfRaw1['Date'].dt.weekofyear

#year week
dfRaw1['YearWeek'] = dfRaw1['Date'].dt.strftime('%Y-%W')

#Competion Sinse
dfRaw1['CompetionSinse'] = dfRaw1.apply(lambda row: datetime.datetime(year=row['CompetitionOpenSinceYear'], month=row['CompetitionOpenSinceMonth'], day=1), axis=1)
dfRaw1['CompetionTimeMonth'] = ((dfRaw1['Date'] - dfRaw1['CompetionSinse'])/30).apply(lambda row: row.days).astype(int)

#Promo Since
dfRaw1['PromoSince'] = dfRaw1['Promo2SinceYear'].astype(str) + '-' + dfRaw1['Promo2SinceWeek'].astype(str)
dfRaw1['PromoSince'] = dfRaw1['PromoSince'].apply(lambda row: datetime.datetime.strptime(row + '-1',  '%Y-%W-%w') - datetime.timedelta(days=7))
dfRaw1['PromoTimeWeek'] = ((dfRaw1['Date'] - dfRaw1['PromoSince'])/7).apply(lambda row: row.days).astype(int)

#Assortment (level: a = basic, b = extra, c = extended)
level = {
    'a' : 'basic', 'b' : 'extra', 'c' : 'extended'
}
dfRaw1['Assortment'] = dfRaw1['Assortment'].map(level)

# State Holiday (a = public holiday, b = Easter holiday, c = Christmas, 0 = None)
holiday = {
    'a' : 'public holiday', 'b' : 'Easter holiday', 'c' : 'Christmas'
}
dfRaw1['StateHoliday'] = dfRaw1['StateHoliday'].map(holiday)
dfRaw1['StateHoliday'].fillna('Regular Day', inplace=True)
dfRaw1.head().T<jupyter_output><empty_output><jupyter_text>Variable Filtering<jupyter_code>dfRaw2 = dfRaw1.copy()<jupyter_output><empty_output><jupyter_text>Row Fitering<jupyter_code>dfRaw2 = dfRaw2[(dfRaw2['Open'] != 0) & (dfRaw2['Sales'] > 0)]<jupyter_output><empty_output><jupyter_text>Columns Filtering<jupyter_code>toDrop = ['Customers', 'Open', 'PromoInterval', 'MonthMap']
dfRaw2.drop(toDrop, axis=1, inplace=True)
dfRaw2.columns<jupyter_output><empty_output><jupyter_text>Convert DataFrame to .csv<jupyter_code>dfRaw2.to_csv('../../01-Data/Results/01-FirstRoundCRISP/dfFeatureEngineering.csv', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18412698412698414, 'fraction_numerical': 0.023809523809523808, 'mean_word_length': 8.302583025830259, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '627767', 'license': 'MIT', 'n_tokens_mistral': 997, 'n_tokens_neox': 976, 'n_words': 133, 'path': '02-Notebooks/01-FirstRoundCRISP/FeatureEngineering.ipynb', 'repo_name': 'FabioCaffarello/Rossmann-Store-Sales', 'size': '2520'}