<jupyter_start><jupyter_text>0.0 Imports<jupyter_code>import math
import pandas as pd
import inflection<jupyter_output><empty_output><jupyter_text>0.1. Helper Functions  0.2. Loading data<jupyter_code>df_sales_0 = pd.read_csv('data/train.csv', low_memory=False)
df_store_0 = pd.read_csv('data/store.csv', low_memory=False)
df_merge = pd.merge(df_sales_0,df_store_0, how='left',on='Store')<jupyter_output><empty_output><jupyter_text>1.0 Descrição dos dados  1.1. Dimensão dos Dados<jupyter_code>print( 'Número de Linhas {}'.format(df_merge.shape[0]))
print( 'Número de Colunas {}'.format(df_merge.shape[1]))<jupyter_output>Número de Linhas 1017209
Número de Colunas 18<jupyter_text>1.2. Tipos de Dados<jupyter_code>df_merge['Date'] = pd.to_datetime(df_merge['Date'])
df_merge.dtypes<jupyter_output><empty_output><jupyter_text>1.1. Verificando Nan<jupyter_code>df_merge.isna().sum()<jupyter_output><empty_output><jupyter_text>1.1. Fillout NA<jupyter_code>df_merge['CompetitionDistance'].max()
# substituição da feature CompetitionDistance com um valor bem alto
df_merge['CompetitionDistance'] = df_merge['CompetitionDistance'].apply( lambda x: 200000.0 if math.isnan(x) else x)
#CompetitionOpenSinceMonth
df_merge['CompetitionOpenSinceMonth'] = df_merge.apply( lambda x: x['Date'].month if math.isnan( x['CompetitionOpenSinceMonth'] ) else x['CompetitionOpenSinceMonth'], axis=1 )

#CompetitionOpenSinceYear
df_merge['CompetitionOpenSinceYear'] = df_merge.apply( lambda x: x['Date'].year if math.isnan( x['CompetitionOpenSinceYear'] ) else x['CompetitionOpenSinceYear'], axis=1 )

#Promo2SinceWeek
df_merge['Promo2SinceWeek'] = df_merge.apply( lambda x: x['Date'].week if math.isnan( x['Promo2SinceWeek'] ) else x['Promo2SinceWeek'], axis=1 )

#Promo2SinceYear
df_merge['Promo2SinceYear'] = df_merge.apply( lambda x: x['Date'].year if math.isnan( x['Promo2SinceYear'] ) else x['Promo2SinceYear'], axis=1 )

#PromoInterval
month_map = {1: 'Jan',  2: 'Fev',  3: 'Mar',  4: 'Apr',  5: 'May',  6: 'Jun',  7: 'Jul',  8: 'Aug',  9: 'Sep',  10: 'Oct', 11: 'Nov', 12: 'Dec'}

df_merge['PromoInterval'].fillna(0, inplace=True )

# Criando uma nova coluna, informando qual é o mês de referencia
df_merge['month_map'] = df_merge['Date'].dt.month.map( month_map )

# Nova coluna contendo informações se a coluna month_map esta contida em promoInterval
df_merge['is_promo'] = df_merge[['PromoInterval', 'month_map']].apply( lambda x: 0 if x['PromoInterval'] == 0 else 1 if x['month_map'] in x['PromoInterval'].split( ',' ) else 0, axis=1 )
df_merge.isna().sum()
df_merge.sample(5).T
#CompetitionDistance
#CompetitionOpenSinceMonth
#CompetitionOpenSinceYear
#Promo2SinceWeek
#Promo2SinceYear
#PromoInterval
df_merge.dtypes
df_merge['CompetitionOpenSinceMonth'] = df_merge['CompetitionOpenSinceMonth'].astype(int)
df_merge['CompetitionOpenSinceYear']  = df_merge['CompetitionOpenSinceYear'].astype(int)

df_merge['Promo2SinceWeek']  = df_merge['Promo2SinceWeek'].astype(int)
df_merge['Promo2SinceYear']  = df_merge['Promo2SinceYear'].astype(int)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14944408109875737, 'fraction_numerical': 0.025506867233485938, 'mean_word_length': 8.441358024691358, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '109484', 'license': 'MIT', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1150, 'n_words': 209, 'path': 'sales_prediction_v2.ipynb', 'repo_name': 'Valmadson/DSProducao', 'size': '3058'}