text_html_output_1.png application_vnd.jupyter.stderr_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

articles_data = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv')
customers_data = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv')
submission_data = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/sample_submission.csv')
trans_data = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')

customers_data_new = customers_data[customers_data['club_member_status'] == 'ACTIVE']

customers_data_new.drop(labels=['FN', 'Active', 'club_member_status', 'fashion_news_frequency'], axis=1, inplace=True)
customers_data_new.reset_index(drop=True, inplace=True)

customers_data_new.drop(labels=['postal_code'], axis=1, inplace=True)
customers_data_new.reset_index(drop=True, inplace=True)

trans_data.dtypes

trans_data['t_dat'] = trans_data['t_dat'].astype('datetime64')
trans_data.dtypes

sample_trans_data = trans_data[trans_data['year_trans'] == 2019]

sample_trans_data.isna().sum()

sample_trans_data.drop(labels=['t_dat', 'sales_channel_id'], axis=1, inplace=True)
sample_trans_data.reset_index(drop=True, inplace=True)

sample_trans_data.isna().sum()

sns.set_style('whitegrid')

interval_range_age = pd.interval_range(start=0, freq=10, end=100)
customers_data_new['age_group'] = pd.cut(customers_data_new['age'], bins=interval_range_age)

customers_data_new.isna().sum()

purchases_2019 = sample_trans_data.merge(customers_data_new, how='left', on='customer_id')

customers_temp = purchases_2019.groupby(['age_group'])['customer_id'].count()
data_temp_customer = pd.DataFrame({
    'Group Age' : customers_temp.index,
    'Customers' : customers_temp.values
})
data_temp_customer = data_temp_customer.sort_values(['Group Age'],ascending=False)
plt.figure(figsize=(7,7))
plt.title(f'Group Age')
sns.set_color_codes('pastel')
s = sns.barplot(x='Group Age', y='Customers', data=data_temp_customer)
s.set_xticklabels(s.get_xticklabels(),rotation=45)
locs, labels = plt.xticks()
plt.show

most_age_group_transaction = purchases_2019[purchases_2019['age_group'] == purchases_2019['age_group'].mode()[0]]
customers_temp_most = most_age_group_transaction.groupby(['day_trans'])['customer_id'].count()
data_temp_customer_most = pd.DataFrame({'Day Transaction': customers_temp_most.index, 'Customers': customers_temp_most.values})
data_temp_customer_most = data_temp_customer_most.sort_values(['Customers'], ascending=False)
plt.figure(figsize=(7, 7))
plt.title(f'Day Transaction of Most Age Group Customers')
sns.set_color_codes('pastel')
s = sns.barplot(x='Day Transaction', y='Customers', data=data_temp_customer_most)
s.set_xticklabels(s.get_xticklabels())
locs, labels = plt.xticks()
plt.show()