<jupyter_start><jupyter_text>0. IMPORTS<jupyter_code>import math
import numpy as np
import pandas as pd
import seaborn as sns
import inflection

from matplotlib import pyplot as plt
from IPython.core.display import HTML<jupyter_output><empty_output><jupyter_text>0.1 Helper Functions<jupyter_code>def jupyter_settings():
    %matplotlib inline
    %pylab inline
    
    plt.style.use( 'bmh' )
    plt.rcParams['figure.figsize'] = [25,12]
    plt.rcParams['font.size'] = 24
    
    display( HTML( '<style>.container {width:100% !important; }</style>') )
    pd.options.display.max_columns = None
    pd.options.display.max_rows = None
    pd.set_option( 'display.expand_frame_repr', False )
    
    sns.set()
jupyter_settings()<jupyter_output>Populating the interactive namespace from numpy and matplotlib<jupyter_text>0.2 Loading Data<jupyter_code>df_sales_raw = pd.read_csv( 'data_csv/train.csv', low_memory= False)
df_store_raw = pd.read_csv( 'data_csv/store.csv', low_memory= False)

# Merge
df_raw = pd.merge( df_sales_raw, df_store_raw, how='left', on='Store' )<jupyter_output><empty_output><jupyter_text>1. DESCRIÇÃO DOS DADOS  1.1 Rename Columns.<jupyter_code>df1 = df_raw.copy()
cols_old = ['Store', 'DayOfWeek', 'Date', 'Sales', 'Customers', 'Open', 'Promo', 'StateHoliday', 'SchoolHoliday', 'StoreType',
            'Assortment', 'CompetitionDistance', 'CompetitionOpenSinceMonth', 'CompetitionOpenSinceYear', 'Promo2',
            'Promo2SinceWeek','Promo2SinceYear', 'PromoInterval']

snakecase = lambda x: inflection.underscore( x )

cols_new = list( map( snakecase, cols_old ) )

# rename
df1.columns = cols_new<jupyter_output><empty_output><jupyter_text>1.2 Data Dimensions<jupyter_code>print( 'Number of Rows: {}'.format( df1.shape[0] ) )
print( 'Number of Cols: {}'.format( df1.shape[1] ) )<jupyter_output>Number of Rows: 1017209
Number of Cols: 18<jupyter_text>1.3 Data Types<jupyter_code>df1['date'] = pd.to_datetime (df1['date'] )<jupyter_output><empty_output><jupyter_text>1.4 Check NA  1.5 Fillout NA<jupyter_code># Competition Distance
df1['competition_distance'] = df1['competition_distance'].apply( lambda x: 200000.0 if math.isnan( x ) else x )

# Competition Open Since Month
df1['competition_open_since_month'] = df1.apply( lambda x: x['date'].month if math.isnan( x['competition_open_since_month'] ) else x['competition_open_since_month'], axis=1 )

# Competition Open Since Year
df1['competition_open_since_year'] = df1.apply( lambda x: x['date'].year if math.isnan( x['competition_open_since_year'] ) else x['competition_open_since_year'], axis=1 )

# Promo2 Since Week
df1['promo2_since_week'] = df1.apply( lambda x: x['date'].week if math.isnan( x['promo2_since_week'] ) else x['promo2_since_week'], axis=1 )

# Promo2 Since Year
df1['promo2_since_year'] = df1.apply( lambda x: x['date'].year if math.isnan( x['promo2_since_year'] ) else x['promo2_since_year'], axis=1 )

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

df1['promo_interval'].fillna(0, inplace=True)

df1['month_map'] = df1['date'].dt.month.map( month_map )

df1['is_promo'] = df1[['promo_interval', 'month_map']].apply( lambda x: 0 if x['promo_interval'] == 0 else 1 if x['month_map'] in x['promo_interval'].split( ',' ) else 0, axis=1 )<jupyter_output><empty_output><jupyter_text>1.6 Change Types<jupyter_code>df1['competition_open_since_month'] = df1['competition_open_since_month'].astype( int )
df1['competition_open_since_year'] = df1['competition_open_since_year'].astype( int )

df1['promo2_since_week'] = df1['promo2_since_week'].astype( int )
df1['promo2_since_year'] = df1['promo2_since_year'].astype( int )<jupyter_output><empty_output><jupyter_text>1.7 Descriptive Statistical  1.7.1 Numerical Categorics<jupyter_code># 
num_attributes = df1.select_dtypes( include=['int32', 'int64', 'float64'] )
cat_attributes = df1.select_dtypes( exclude=['int32', 'int64', 'float64', 'datetime64[ns]'] )
# Central Tendency - mean, median
ct1 = pd.DataFrame( num_attributes.apply( np.mean ) ).T
ct2 = pd.DataFrame( num_attributes.apply( np.median ) ).T

# Dispersion - std, min, max, range, skew, kurtosis
d1 = pd.DataFrame( num_attributes.apply( np.std ) ).T
d2 = pd.DataFrame( num_attributes.apply( min ) ).T
d3 = pd.DataFrame( num_attributes.apply( max ) ).T
d4 = pd.DataFrame( num_attributes.apply( lambda x: x.max() - x.min() ) ).T
d5 = pd.DataFrame( num_attributes.apply( lambda x: x.skew() ) ).T
d6 = pd.DataFrame( num_attributes.apply( lambda x: x.kurtosis() ) ).T

# Concatenar
m = pd.concat( [ d2, d3, d4, ct1, ct2, d1, d5, d6 ] ).T.reset_index()
m.columns = ['attributes', 'min', 'max', 'range', 'mean', 'median', 'std', 'skew', 'kurtosis']
m
sns.displot( df1['competition_distance'] )<jupyter_output><empty_output><jupyter_text>1.7.2 Categorical Attributes<jupyter_code>cat_attributes.apply( lambda x: x.unique().shape[0] )
aux1 = df1[(df1['state_holiday'] != '0') & (df1['sales'] > 0)]

plt.subplot(1,3,1)
sns.boxplot( x='state_holiday', y='sales', data=aux1 )

plt.subplot(1,3,2)
sns.boxplot( x='store_type', y='sales', data=aux1 )

plt.subplot(1,3,3)
sns.boxplot( x='assortment', y='sales', data=aux1 )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16517602283539487, 'fraction_numerical': 0.03311132254995243, 'mean_word_length': 6.170532060027285, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 42, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '471418', 'license': 'MIT', 'n_tokens_mistral': 2128, 'n_tokens_neox': 2050, 'n_words': 411, 'path': 'notebooks/m02_v01_store_sales_prediction.ipynb', 'repo_name': 'RPerottoni/Rossmann_Sales_Prediction', 'size': '5255'}