{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"**PLEASE UPVOTE https://www.kaggle.com/code/datark1/detailed-eda-understanding-h-m-data**","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport datetime as dt\n\nprint(f'PANDAS VERSION: {pd.__version__}')\nprint(f'NUMPY VERSION: {np.__version__}')\nprint(f'SNS VERSION: {sns.__version__}')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:31:36.276043Z","iopub.execute_input":"2022-03-26T14:31:36.276909Z","iopub.status.idle":"2022-03-26T14:31:37.158697Z","shell.execute_reply.started":"2022-03-26T14:31:36.276808Z","shell.execute_reply":"2022-03-26T14:31:37.157082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"art = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/articles.csv')\ncust = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/customers.csv')\ntrans = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:31:37.164614Z","iopub.execute_input":"2022-03-26T14:31:37.165244Z","iopub.status.idle":"2022-03-26T14:32:42.455232Z","shell.execute_reply.started":"2022-03-26T14:31:37.165198Z","shell.execute_reply":"2022-03-26T14:32:42.454480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# art","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:42.456520Z","iopub.execute_input":"2022-03-26T14:32:42.457016Z","iopub.status.idle":"2022-03-26T14:32:42.460739Z","shell.execute_reply.started":"2022-03-26T14:32:42.456981Z","shell.execute_reply":"2022-03-26T14:32:42.459972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# cust","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:42.463648Z","iopub.execute_input":"2022-03-26T14:32:42.463940Z","iopub.status.idle":"2022-03-26T14:32:42.473418Z","shell.execute_reply.started":"2022-03-26T14:32:42.463907Z","shell.execute_reply":"2022-03-26T14:32:42.472741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# trans","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:42.475658Z","iopub.execute_input":"2022-03-26T14:32:42.476339Z","iopub.status.idle":"2022-03-26T14:32:42.486163Z","shell.execute_reply.started":"2022-03-26T14:32:42.476296Z","shell.execute_reply":"2022-03-26T14:32:42.485401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib as mpl\nmpl.rcParams.update(mpl.rcParamsDefault)\n\ndata = art\nart_dtypes = art.dtypes.value_counts()\n\nfig = plt.figure(figsize=(5, 2), facecolor='mistyrose')\n\nax_0 = fig.add_subplot(1, 1, 1)\nfont = 'monospace'\n\nax_0.text(1, \n          0.8, \n          'KEY FIGURES',\n          color='turquoise',\n          fontsize=20,\n          fontweight='bold',\n          fontfamily=font,\n          ha='center')\nax_0.text(0,\n          0.4,\n          f'{data.shape[0]:,d}', \n          color='cyan', \n          fontsize=16, \n          fontweight='bold', \n          fontfamily=font, \n          ha='center')\nax_0.text(0, \n          0.001, \n          'DATASET ROWS NUMBER',\n          color='darkcyan',\n          fontsize=10,\n          fontweight='light',\n          fontfamily=font,\n          ha='center')\nax_0.text(0.6,\n          0.4,\n          f'{data.shape[1]}',\n          color='cyan',\n          fontsize=16, \n          fontweight='bold', \n          fontfamily=font,\n          ha='center')\nax_0.text(0.6, \n          0.001, \n          'DATASET FEATURES NUMBER',\n          color='darkcyan',\n          fontsize=10,\n          fontweight='light',\n          fontfamily=font,\n          ha='center')\nax_0.text(1.2,\n          0.4,\n          f'{art_dtypes[0]}',\n          color='cyan',\n          fontsize=16, \n          fontweight='bold', \n          fontfamily=font,\n          ha='center')\nax_0.text(1.2, \n          0.001, \n          'DATASET TEXT COLUMNS NUMBER',\n          color='darkcyan',\n          fontsize=10,\n          fontweight='light',\n          fontfamily=font,\n          ha='center')\nax_0.text(1.9,\n          0.4,\n          f'{art_dtypes[1]}',\n          color='cyan',\n          fontsize=16, \n          fontweight='bold', \n          fontfamily=font,\n          ha='center')\nax_0.text(1.9, \n          0.001, \n          'DATASET NUMERIC COLUMNS NUMBER',\n          color='darkcyan',\n          fontsize=10,\n          fontweight='light',\n          fontfamily=font,\n          ha='center')\n\nax_0.set_xticklabels('')\nax_0.tick_params(axis='x', length=0)\nax_0.tick_params(axis='y', length=0)\nax_0.set_yticklabels('')\n\nfor spine in ['top', 'right', 'bottom', 'left']:\n    ax_0.spines[spine].set_visible(False)\n    \nfig.subplots_adjust(top=0.9, bottom=0.2, left=0, hspace=1)\n\nfig.patch.set_linewidth(5)\nfig.patch.set_edgecolor('darkgray')\nfig.patch.set_facecolor('lightgray')\nax_0.set_facecolor('lightgray')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:42.487393Z","iopub.execute_input":"2022-03-26T14:32:42.488024Z","iopub.status.idle":"2022-03-26T14:32:42.704672Z","shell.execute_reply.started":"2022-03-26T14:32:42.487988Z","shell.execute_reply":"2022-03-26T14:32:42.704087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"art.isna().sum() / len(art) * 100","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:42.705593Z","iopub.execute_input":"2022-03-26T14:32:42.706366Z","iopub.status.idle":"2022-03-26T14:32:42.877638Z","shell.execute_reply.started":"2022-03-26T14:32:42.706325Z","shell.execute_reply":"2022-03-26T14:32:42.876773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from os import walk\n\ndef show_articles(folder, no_images=3):\n    folder_path = f'../input/h-and-m-personalized-fashion-recommendations/images/{folder}/'\n    files = []\n    \n    for _, _, filenames in walk(folder_path):\n        files.extend(filenames)\n    no_files = len(files)\n    if no_images > no_files:\n        no_images = no_files\n        print('WARNING! IN FOLDER IMAGES ARE LESS THAN REQUESTED')\n        \n    images = files[:no_images]\n    fig, ax = plt.subplots(1, no_images, figsize=(12, 4))\n    \n    for i, image in enumerate(images):\n        art_id = image.split('.')[0]\n        image = plt.imread(folder_path+image)\n        ax[i].imshow(image, aspect='equal')\n        ax[i].grid(False)\n        ax[i].set_xticks([], [])\n        ax[i].set_yticks([], [])\n        ax[i].set_xlabel(art[art['article_id'] == int(art_id[1:])]['prod_name'].iloc[0])\n    \n    plt.show()\n    \nshow_articles('020', 4)","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:42.878956Z","iopub.execute_input":"2022-03-26T14:32:42.879180Z","iopub.status.idle":"2022-03-26T14:32:44.628737Z","shell.execute_reply.started":"2022-03-26T14:32:42.879152Z","shell.execute_reply":"2022-03-26T14:32:44.627944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.ticker as mtick\n\ndef plot_bar(database, col, figsize=(13, 5), pct=False, label='ARTICLES'):\n    fig, ax = plt.subplots(figsize=figsize, facecolor='lemonchiffon')\n    \n    for spine in ['bottom', 'left']:\n        ax.spines[spine].set_visible(True)\n        ax.spines[spine].set_linewidth(2)\n        ax.spines[spine].set_color('goldenrod')\n        \n    ax.spines['top'].set_visible(False)\n    ax.spines['right'].set_visible(False)\n    \n    if pct:\n        data = database[col].value_counts()\n        data = data.div(data.sum()).mul(100)\n        data = data.reset_index()\n        ax = sns.barplot(data=data, x=col, y='index', color='gold', lw=1.5, ec='olive', zorder=2)\n        ax.set_xlabel(f'% OF {label}', color='goldenrod', fontsize=10, weight='bold')\n        ax.xaxis.set_major_formatter(mtick.PercentFormatter())\n    else:\n        data = database[col].value_counts().reset_index()\n        ax = sns.barplot(data=data, x=col, y='index', color='darkgoldenrod', lw=1.5, ec='olive', zorder=2)\n        ax.set_xlabel(f'{label} NUMBER',color='gold', fontsize=10, weight='bold')\n        \n    ax.grid(zorder=0)\n    ax.text(0, -0.75, col, color='goldenrod', fontsize=10, ha='left', va='bottom', weight='bold', style='italic')\n    ax.set_ylabel('')\n    \n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:44.630179Z","iopub.execute_input":"2022-03-26T14:32:44.630426Z","iopub.status.idle":"2022-03-26T14:32:44.644765Z","shell.execute_reply.started":"2022-03-26T14:32:44.630398Z","shell.execute_reply":"2022-03-26T14:32:44.643698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style('darkgrid', {'axes.facecolor': '0.9'})\nplot_bar(art, 'index_group_name', pct=True)","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:44.646576Z","iopub.execute_input":"2022-03-26T14:32:44.647714Z","iopub.status.idle":"2022-03-26T14:32:44.965821Z","shell.execute_reply.started":"2022-03-26T14:32:44.647650Z","shell.execute_reply":"2022-03-26T14:32:44.964559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_bar(art, 'index_name', pct=True)","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:44.967568Z","iopub.execute_input":"2022-03-26T14:32:44.968037Z","iopub.status.idle":"2022-03-26T14:32:45.296367Z","shell.execute_reply.started":"2022-03-26T14:32:44.967991Z","shell.execute_reply":"2022-03-26T14:32:45.295722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"art_divided = art[art['index_name'] == 'Divided']\nart_divided[['prod_name', 'product_type_name', 'detail_desc', 'index_name', 'section_name', 'garment_group_name']].drop_duplicates().head(12)","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:45.297367Z","iopub.execute_input":"2022-03-26T14:32:45.297716Z","iopub.status.idle":"2022-03-26T14:32:45.357600Z","shell.execute_reply.started":"2022-03-26T14:32:45.297671Z","shell.execute_reply":"2022-03-26T14:32:45.356627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def show_items_in_category(column, value, no_images=4, title=None):\n    data = art[art[column] == value]\n    article_ids = data['article_id'].iloc[:no_images].to_list()\n    \n    fig, ax = plt.subplots(1, no_images, figsize=(12, 4))\n    \n    for i, article_id in enumerate(article_ids):\n        folder = str(article_id)[:2]\n        file_path = f'../input/h-and-m-personalized-fashion-recommendations/images/0{folder}/0{article_id}.jpg'\n        \n        image = plt.imread(file_path)\n        ax[i].imshow(image, aspect='equal')\n        ax[i].grid(False)\n        ax[i].set_xticks([], [])\n        ax[i].set_yticks([], [])\n        ax[i].set_xlabel(art[art['article_id'] == int(article_id)]['prod_name'].iloc[0])\n        \n    fig.suptitle(title)\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:45.362428Z","iopub.execute_input":"2022-03-26T14:32:45.363065Z","iopub.status.idle":"2022-03-26T14:32:45.373261Z","shell.execute_reply.started":"2022-03-26T14:32:45.363011Z","shell.execute_reply":"2022-03-26T14:32:45.371969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_items_in_category('index_name', 'Divided', 5, '\"DIVIDED\" CATEGORY ARTICLES')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:45.375134Z","iopub.execute_input":"2022-03-26T14:32:45.375481Z","iopub.status.idle":"2022-03-26T14:32:47.311602Z","shell.execute_reply.started":"2022-03-26T14:32:45.375433Z","shell.execute_reply":"2022-03-26T14:32:47.310822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"art.groupby(['index_group_name', 'index_name']).size()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:47.313468Z","iopub.execute_input":"2022-03-26T14:32:47.313803Z","iopub.status.idle":"2022-03-26T14:32:47.348120Z","shell.execute_reply.started":"2022-03-26T14:32:47.313759Z","shell.execute_reply":"2022-03-26T14:32:47.347198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_bar(art, 'product_group_name', pct=True)","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:47.349375Z","iopub.execute_input":"2022-03-26T14:32:47.349591Z","iopub.status.idle":"2022-03-26T14:32:47.778928Z","shell.execute_reply.started":"2022-03-26T14:32:47.349566Z","shell.execute_reply":"2022-03-26T14:32:47.777952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = art['product_group_name'].value_counts()\ndata = data.div(data.sum()).mul(100)\npareto = data.cumsum().rename('cumulative_pct')\npareto","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:47.780549Z","iopub.execute_input":"2022-03-26T14:32:47.780871Z","iopub.status.idle":"2022-03-26T14:32:47.808847Z","shell.execute_reply.started":"2022-03-26T14:32:47.780828Z","shell.execute_reply":"2022-03-26T14:32:47.807929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pareto.reset_index()\ndata.columns = ['group', 'cumulative_pct']\ndata.index += 1\ndata['cumulative_pct'][6] / 100","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:47.810695Z","iopub.execute_input":"2022-03-26T14:32:47.811091Z","iopub.status.idle":"2022-03-26T14:32:47.823899Z","shell.execute_reply.started":"2022-03-26T14:32:47.811048Z","shell.execute_reply":"2022-03-26T14:32:47.822868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(15, 5))\n\ndata = pareto.reset_index()\ndata.columns = ['features', 'cumulative_pct']\ndata.index += 1\n\nsns.lineplot(data=data, x=data.index, y='cumulative_pct', color='deeppink')\n\nfor spine in ['bottom', 'left']:\n    ax.spines[spine].set_visible(True)\n    ax.spines[spine].set_linewidth(2)\n    ax.spines[spine].set_color('maroon')\n    \nax.set_xticks(pareto.reset_index().index)\nax.yaxis.set_major_formatter(mtick.PercentFormatter())\nax.set_ylabel('CUMULATIVE PERCENTAGE', color='lightpink')\nax.set_xlabel('PRODUCT GROUPS NUMBER', color='lightpink')\nax.set_xlim(1)\nax.set_ylim(data['cumulative_pct'][1])\n\nax.vlines(7, data['cumulative_pct'][1], data['cumulative_pct'][7], color='pink', ls = '--')\nax.hlines(data['cumulative_pct'][7], 1, 7, color='pink', ls = '--')\nax.text(0,\n        1.05,\n        'PRODUCT GROUPS PARETO GRAPH',\n        color='crimson',\n        fontsize=10,\n        ha='left',\n        va='bottom',\n        weight='bold',\n        style='italic',\n        transform=ax.transAxes)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:47.825357Z","iopub.execute_input":"2022-03-26T14:32:47.825599Z","iopub.status.idle":"2022-03-26T14:32:48.352384Z","shell.execute_reply.started":"2022-03-26T14:32:47.825572Z","shell.execute_reply":"2022-03-26T14:32:48.351627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for group in art['product_group_name'].unique():\n    print(f\"'{group.upper()}' SUBCATEGORIES NUMBER: {len(art.groupby(['product_group_name', 'product_type_name']).size()[group])}\")","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:48.353580Z","iopub.execute_input":"2022-03-26T14:32:48.354575Z","iopub.status.idle":"2022-03-26T14:32:48.819039Z","shell.execute_reply.started":"2022-03-26T14:32:48.354523Z","shell.execute_reply":"2022-03-26T14:32:48.818024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndef plot_bar_colors(database, col, figsize=(13, 5), pct=False, label='ARTICLES'):\n    fig, ax = plt.subplots(figsize=figsize, facecolor='lemonchiffon')\n    \n    for spine in ['bottom', 'left']:\n        ax.spines[spine].set_visible(True)\n        ax.spines[spine].set_linewidth(2)\n        ax.spines[spine].set_color('goldenrod')\n        \n    ax.spines['top'].set_visible(False)\n    ax.spines['right'].set_visible(False)\n    \n    if pct:\n        data = database[col].value_counts()\n        data = data.div(data.sum()).mul(100)\n        data = data.reset_index()\n        colors = {\n            'Dark Blue': '#0a007d',\n            'Black': '#000000',\n            'White': '#ffffff',\n            'Light Pink': '#ffa6de',\n            'Grey': '#7a7a7a',\n            'Light Beige': '#ffe6b0',\n            'Blue': '#0d00ff',\n            'Red': '#ff0000',\n            'Light Blue': '#80ccff',\n            'Greenish Khaki': '#665923',\n            'Dark Grey': '#5c5c5c',\n            'Off White': '#fff7e0',\n            'Beige': '#ffdb87',\n            'Dark Red': '#700002',\n            'Dark Green': '#064a00',\n            'Light Grey': '#b8b8b8',\n            'Pink': '#ff00d9',\n            'Yellow': '#fff700',\n            'Light Orange': '#ff872b',\n            'Yellowish Brown': '#6e3e00',\n            'Gold': '#ffc400',\n            'Dark Beige': '#a6853a',\n            'Light Turquoise': '#82ffd5',\n            'Light Yellow': '#ffff82',\n            'Dark Orange': '#913300',\n            'Dark Pink': '#8f0051',\n            'Green': '#00ff1e',\n            'Orange': '#ff8000',\n            'Other Pink': '#b32972',\n            'Silver': '#d4d4d4',\n            'Light Green': '#88ff61',\n            'Dark Yellow': '#968f00',\n            'Light Purple': '#c56eff',\n            'Dark Turquoise': '#006955',\n            'Turquoise': '#00ffd0',\n            'Dark Purple': '#580073',\n            'Light Red': '#ff4f4f',\n            'Greyish Beige': '#b8a681',\n            'Other Yellow': '#bfbb32',\n            'Purple': '#c300ff',\n            'Other Orange': '#a64800',\n            'Other Green': '#2e4730',\n            'Other Red': '#8c0f35',\n            'Other': '#755d49',\n            'Bronze/Copper': '#994700',\n            'Other Blue': '#32457d', \n            'Other Purple': '#6f3885',\n            'Transparent': '#65883a',\n            'Unknown': '#474f57',\n            'Other Turquoise': '#5cffcb'\n        }\n        \n#         palette = [colors[name] for name in data['index'].values]\n        palette = map(lambda name: colors[name], data['index'].values)\n        ax = sns.barplot(data=data, x=col, y='index', palette=palette, lw=1.5, ec='olive', zorder=2)\n        ax.set_xlabel(f'% OF {label}', color='goldenrod', fontsize=10, weight='bold')\n        ax.xaxis.set_major_formatter(mtick.PercentFormatter())\n    else:\n        data = database[col].value_counts().reset_index()\n        ax = sns.barplot(data=data, x=col, y='index', color='darkgoldenrod', lw=1.5, ec='olive', zorder=2)\n        ax.set_xlabel(f'{label} NUMBER',color='gold', fontsize=10, weight='bold')\n        \n    ax.grid(zorder=0)\n    ax.text(0, -0.75, col, color='goldenrod', fontsize=10, ha='left', va='bottom', weight='bold', style='italic')\n    ax.set_ylabel('')\n    \n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:48.820466Z","iopub.execute_input":"2022-03-26T14:32:48.820788Z","iopub.status.idle":"2022-03-26T14:32:48.841573Z","shell.execute_reply.started":"2022-03-26T14:32:48.820742Z","shell.execute_reply":"2022-03-26T14:32:48.840700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_bar_colors(art, 'colour_group_name', figsize=(15, 12), pct=True)","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:48.843145Z","iopub.execute_input":"2022-03-26T14:32:48.843401Z","iopub.status.idle":"2022-03-26T14:32:49.827786Z","shell.execute_reply.started":"2022-03-26T14:32:48.843373Z","shell.execute_reply":"2022-03-26T14:32:49.826915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_bar(art, 'perceived_colour_value_name', pct=True)","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:49.829361Z","iopub.execute_input":"2022-03-26T14:32:49.829806Z","iopub.status.idle":"2022-03-26T14:32:50.161538Z","shell.execute_reply.started":"2022-03-26T14:32:49.829757Z","shell.execute_reply":"2022-03-26T14:32:50.160649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_items_in_category('perceived_colour_value_name', 'Dusty Light', 5, 'DUSTY LIGHT ARTICLES')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:50.163233Z","iopub.execute_input":"2022-03-26T14:32:50.163768Z","iopub.status.idle":"2022-03-26T14:32:52.075852Z","shell.execute_reply.started":"2022-03-26T14:32:50.163719Z","shell.execute_reply":"2022-03-26T14:32:52.074937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndef plot_bar_colors(database, col, figsize=(13, 5), pct=False, label='ARTICLES'):\n    fig, ax = plt.subplots(figsize=figsize, facecolor='lemonchiffon')\n    \n    for spine in ['bottom', 'left']:\n        ax.spines[spine].set_visible(True)\n        ax.spines[spine].set_linewidth(2)\n        ax.spines[spine].set_color('goldenrod')\n        \n    ax.spines['top'].set_visible(False)\n    ax.spines['right'].set_visible(False)\n    \n    if pct:\n        data = database[col].value_counts()\n        data = data.div(data.sum()).mul(100)\n        data = data.reset_index()\n        colors = {\n            'White': '#ffffff',\n            'Black': '#000000',\n            'Beige': '#ffdb87',\n            'Grey': '#7a7a7a',\n            'Blue': '#0d00ff',\n            'Pink': '#ff00d9',\n            'Lilac Purple': '#8000ff',\n            'Red': '#ff0000',\n            'Mole': '#ffb36b',\n            'Orange': '#ff8000',\n            'Metal': '#bdbdbd',\n            'Brown': '#3d1700',\n            'Turquoise': '#00ffd0',\n            'Yellow': '#fff700',\n            'Khaki green': '#9c7a00',\n            'Green': '#00ff1e',\n            'undefined': '#919191',\n            'Unknown': '#545454',\n            'Yellowish Green': '#fbff00',\n            'Bluish Green': '#00ffb3'\n        }\n        \n#         palette = [colors[name] for name in data['index'].values]\n        palette = map(lambda name: colors[name], data['index'].values)\n        ax = sns.barplot(data=data, x=col, y='index', palette=palette, lw=1.5, ec='olive', zorder=2)\n        ax.set_xlabel(f'% OF {label}', color='goldenrod', fontsize=10, weight='bold')\n        ax.xaxis.set_major_formatter(mtick.PercentFormatter())\n    else:\n        data = database[col].value_counts().reset_index()\n        ax = sns.barplot(data=data, x=col, y='index', color='darkgoldenrod', lw=1.5, ec='olive', zorder=2)\n        ax.set_xlabel(f'{label} NUMBER',color='gold', fontsize=10, weight='bold')\n        \n    ax.grid(zorder=0)\n    ax.text(0, -0.75, col, color='goldenrod', fontsize=10, ha='left', va='bottom', weight='bold', style='italic')\n    ax.set_ylabel('')\n    \n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:52.076932Z","iopub.execute_input":"2022-03-26T14:32:52.077506Z","iopub.status.idle":"2022-03-26T14:32:52.093192Z","shell.execute_reply.started":"2022-03-26T14:32:52.077469Z","shell.execute_reply":"2022-03-26T14:32:52.092296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_bar_colors(art, 'perceived_colour_master_name', pct=True)","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:52.095111Z","iopub.execute_input":"2022-03-26T14:32:52.095464Z","iopub.status.idle":"2022-03-26T14:32:52.528020Z","shell.execute_reply.started":"2022-03-26T14:32:52.095416Z","shell.execute_reply":"2022-03-26T14:32:52.527177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_bar(art, 'graphical_appearance_name', figsize=(14, 7), pct=True)","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:52.529434Z","iopub.execute_input":"2022-03-26T14:32:52.529772Z","iopub.status.idle":"2022-03-26T14:32:53.028479Z","shell.execute_reply.started":"2022-03-26T14:32:52.529740Z","shell.execute_reply":"2022-03-26T14:32:53.027784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_items_in_category('graphical_appearance_name', 'All over pattern', 5, 'ALL OVER PATTERN')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:53.029794Z","iopub.execute_input":"2022-03-26T14:32:53.030306Z","iopub.status.idle":"2022-03-26T14:32:55.004574Z","shell.execute_reply.started":"2022-03-26T14:32:53.030268Z","shell.execute_reply":"2022-03-26T14:32:55.003903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_items_in_category('graphical_appearance_name', 'Melange', 5, 'MELANGE')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:55.005559Z","iopub.execute_input":"2022-03-26T14:32:55.006290Z","iopub.status.idle":"2022-03-26T14:32:56.487450Z","shell.execute_reply.started":"2022-03-26T14:32:55.006257Z","shell.execute_reply":"2022-03-26T14:32:56.483888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_items_in_category('graphical_appearance_name', 'Glittering/Metallic', 5, 'GLITTERING/METALLIC')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:56.488817Z","iopub.execute_input":"2022-03-26T14:32:56.489719Z","iopub.status.idle":"2022-03-26T14:32:58.360773Z","shell.execute_reply.started":"2022-03-26T14:32:56.489672Z","shell.execute_reply":"2022-03-26T14:32:58.359931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_items_in_category('graphical_appearance_name', 'Lace', 5, 'LACE')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:32:58.362286Z","iopub.execute_input":"2022-03-26T14:32:58.362755Z","iopub.status.idle":"2022-03-26T14:33:00.699800Z","shell.execute_reply.started":"2022-03-26T14:32:58.362717Z","shell.execute_reply":"2022-03-26T14:33:00.698772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"show_items_in_category('graphical_appearance_name', 'Embroidery', 5, 'EMBROIDERY')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:00.701127Z","iopub.execute_input":"2022-03-26T14:33:00.701357Z","iopub.status.idle":"2022-03-26T14:33:02.542044Z","shell.execute_reply.started":"2022-03-26T14:33:00.701330Z","shell.execute_reply":"2022-03-26T14:33:02.540941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"art['detail_desc'].drop_duplicates().to_list()[:10]","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:02.543790Z","iopub.execute_input":"2022-03-26T14:33:02.544183Z","iopub.status.idle":"2022-03-26T14:33:02.571561Z","shell.execute_reply.started":"2022-03-26T14:33:02.544132Z","shell.execute_reply":"2022-03-26T14:33:02.570614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import nltk\nfrom nltk.corpus import stopwords\nfrom wordcloud import WordCloud, STOPWORDS\nfrom PIL import Image\n\nwords_raw = art['detail_desc'].dropna().apply(nltk.word_tokenize)\nbag_of_words = ' '.join(words_raw.explode())\nstopwords = set(STOPWORDS)\n\nfig, ax_1 = plt.subplots(figsize=(8, 6))\nword_cloud = WordCloud(stopwords=stopwords,\n                       colormap='spring',\n                       background_color='crimson',\n                       height=300, \n                       contour_width=3,).generate(bag_of_words)\nplt.imshow(word_cloud, interpolation='bilinear')\n# plt.imshow(wordcloud_por.recolor(color_func=image_colors), interpolation=\"bilinear\")\nplt.axis('off')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:02.572791Z","iopub.execute_input":"2022-03-26T14:33:02.573247Z","iopub.status.idle":"2022-03-26T14:33:55.605860Z","shell.execute_reply.started":"2022-03-26T14:33:02.573198Z","shell.execute_reply":"2022-03-26T14:33:55.604928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mpl.rcParams.update(mpl.rcParamsDefault)\n\ncust_dtypes = cust.dtypes.value_counts()\ndata = cust\n\nfig = plt.figure(figsize=(5, 2), facecolor='lightcyan')\nax_0 = fig.add_subplot(1, 1, 1)\n\nax_0.text(1.0,\n          1,\n          'KEY FIGURES',\n          color='grey',\n          fontsize=20, \n          fontweight='bold',\n          fontfamily='monospace',\n          ha='center')\n\nax_0.text(0,\n          0.4,\n          f'{data.shape[0]:,d}',\n          color='turquoise',\n          fontsize=18, \n          fontweight='bold',\n          fontfamily='monospace',\n          ha='center')\nax_0.text(0,\n          0.001,\n          'DATASET ROWS NUMBER',\n          color='dimgrey',\n          fontsize=10, \n          fontweight='light',\n          fontfamily='monospace',\n          ha='center')\n\nax_0.text(0.6,\n          0.4,\n          f'{data.shape[1]}',\n          color='turquoise',\n          fontsize=18, \n          fontweight='bold',\n          fontfamily='monospace',\n          ha='center')\nax_0.text(0.6,\n          0.001,\n          'DATASET FEATURES NUMBER',\n          color='dimgrey',\n          fontsize=10, \n          fontweight='light',\n          fontfamily='monospace',\n          ha='center')\n\nax_0.text(1.2,\n          0.4,\n          f'{cust_dtypes[0]}',\n          color='turquoise',\n          fontsize=18, \n          fontweight='bold',\n          fontfamily='monospace',\n          ha='center')\nax_0.text(1.2,\n          0.001,\n          'DATASET TEXT COLUMNS NUMBER',\n          color='dimgrey',\n          fontsize=10, \n          fontweight='light',\n          fontfamily='monospace',\n          ha='center')\n\nax_0.text(1.9,\n          0.4,\n          f'{cust_dtypes[1]}',\n          color='turquoise',\n          fontsize=18, \n          fontweight='bold',\n          fontfamily='monospace',\n          ha='center')\nax_0.text(1.9,\n          0.001,\n          'DATASET NUMERIC COLUMNS NUMBER',\n          color='dimgrey',\n          fontsize=10, \n          fontweight='light',\n          fontfamily='monospace',\n          ha='center')\nax_0.set_xticklabels('')\nax_0.tick_params(axis='x', length=1)\nax_0.tick_params(axis='y', length=1)\nax_0.set_yticklabels('')\n\nfor spine in ['top', 'right', 'bottom', 'left']:\n    ax_0.spines[spine].set_visible(False)\n    \nfig.patch.set_linewidth(5)\nfig.patch.set_edgecolor('darkcyan')\nfig.patch.set_facecolor('azure')\n\nax_0.set_facecolor('azure')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:55.607621Z","iopub.execute_input":"2022-03-26T14:33:55.607996Z","iopub.status.idle":"2022-03-26T14:33:55.804500Z","shell.execute_reply.started":"2022-03-26T14:33:55.607948Z","shell.execute_reply":"2022-03-26T14:33:55.803636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cust.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:55.805956Z","iopub.execute_input":"2022-03-26T14:33:55.806285Z","iopub.status.idle":"2022-03-26T14:33:56.446289Z","shell.execute_reply.started":"2022-03-26T14:33:55.806239Z","shell.execute_reply":"2022-03-26T14:33:56.445195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cust_backup = cust.copy()\ncust[['FN', 'Active']] = cust[['FN', 'Active']].fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:56.447930Z","iopub.execute_input":"2022-03-26T14:33:56.448255Z","iopub.status.idle":"2022-03-26T14:33:56.546753Z","shell.execute_reply.started":"2022-03-26T14:33:56.448214Z","shell.execute_reply":"2022-03-26T14:33:56.545947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(5, 5))\nexplode = (0, 0.1)\ncolors = sns.color_palette('prism')\n\nax.pie(cust['FN'].value_counts(),\n       explode=explode,\n       labels=['NOT FN', 'FN'],\n       autopct='%1.1f%%',\n       shadow=True,\n       startangle=90,\n       colors=colors)\nax.axis('equal')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:56.547956Z","iopub.execute_input":"2022-03-26T14:33:56.548168Z","iopub.status.idle":"2022-03-26T14:33:56.703218Z","shell.execute_reply.started":"2022-03-26T14:33:56.548141Z","shell.execute_reply":"2022-03-26T14:33:56.702035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(5, 5))\nexplode = (0, 0.1)\ncolors = sns.color_palette('gist_ncar')\n\nax.pie(cust['Active'].value_counts(),\n       explode=explode,\n       labels=['NOT ACTIVE', 'ACTIVE'],\n       autopct='%1.1f%%',\n       shadow=True,\n       startangle=90,\n       colors=colors)\nax.axis('equal')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:56.705308Z","iopub.execute_input":"2022-03-26T14:33:56.705677Z","iopub.status.idle":"2022-03-26T14:33:56.885961Z","shell.execute_reply.started":"2022-03-26T14:33:56.705631Z","shell.execute_reply":"2022-03-26T14:33:56.884758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"FN_Active = len(cust[(cust['FN'] == 1) & (cust['Active'] == 1)]) / cust.shape[0] * 100\nprint(f'PERCENTAGE FN AND ACTIVE CUSTOMER STATUS: {round(FN_Active, 2)} %')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:56.896352Z","iopub.execute_input":"2022-03-26T14:33:56.896801Z","iopub.status.idle":"2022-03-26T14:33:56.996349Z","shell.execute_reply.started":"2022-03-26T14:33:56.896752Z","shell.execute_reply":"2022-03-26T14:33:56.995479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"FN_not_Active = len(cust[(cust['FN'] == 1) & (cust['Active'] != 1)]) / cust.shape[0] * 100\nprint(f'PERCENTAGE FN AND NOT ACTIVE CUSTOMER STATUS: {round(FN_not_Active, 2)} %')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:56.997671Z","iopub.execute_input":"2022-03-26T14:33:56.997949Z","iopub.status.idle":"2022-03-26T14:33:57.021979Z","shell.execute_reply.started":"2022-03-26T14:33:56.997910Z","shell.execute_reply":"2022-03-26T14:33:57.021369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cust['club_member_status'] = cust['club_member_status'].fillna('N/A')\nsns.set_style('darkgrid', {'axes.facecolor': '.9'})\nplot_bar(cust, 'club_member_status', pct=True, label='CUSTOMERS')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:57.022941Z","iopub.execute_input":"2022-03-26T14:33:57.023668Z","iopub.status.idle":"2022-03-26T14:33:57.644718Z","shell.execute_reply.started":"2022-03-26T14:33:57.023624Z","shell.execute_reply":"2022-03-26T14:33:57.644142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cust['fashion_news_frequency'] = cust['fashion_news_frequency'].fillna('N/A')\nplot_bar(cust, 'fashion_news_frequency', pct=True, label='CUSTOMERS')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:57.645846Z","iopub.execute_input":"2022-03-26T14:33:57.646239Z","iopub.status.idle":"2022-03-26T14:33:58.289284Z","shell.execute_reply.started":"2022-03-26T14:33:57.646209Z","shell.execute_reply":"2022-03-26T14:33:58.288438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(10, 5))\nax = sns.histplot(data=cust, x='age', bins=cust['age'].nunique(), color='deeppink', stat='percent')\nax.set_xlabel('CUSTOMER AGE DISTRIBUTION')\n\nfor spine in ['bottom', 'left']:\n    ax.spines[spine].set_visible(True)\n    ax.spines[spine].set_linewidth(2)\n    ax.spines[spine].set_color('grey')\n    \nax.yaxis.set_major_formatter(mtick.PercentFormatter())\nmedian = cust['age'].median()\nax.axvline(x=median, color='darkred', ls='--')\nax.text(median, 3.5, f'MEDIAN: {round(median, 1)}', rotation='vertical', ha='right')\nax.text(12,\n        5.5,\n        'CUSTOMERS AGE DISTRIBUTION',\n        color='darkgrey',\n        fontsize=10,\n        ha='left',\n        va='bottom',\n        weight='bold',\n        style='italic')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:58.290537Z","iopub.execute_input":"2022-03-26T14:33:58.290919Z","iopub.status.idle":"2022-03-26T14:33:58.992986Z","shell.execute_reply.started":"2022-03-26T14:33:58.290866Z","shell.execute_reply":"2022-03-26T14:33:58.992035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"THE OLDEST CUSTOMER IS {cust['age'].max()} YEARS OLD.\")","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:58.994429Z","iopub.execute_input":"2022-03-26T14:33:58.994756Z","iopub.status.idle":"2022-03-26T14:33:59.002506Z","shell.execute_reply.started":"2022-03-26T14:33:58.994710Z","shell.execute_reply":"2022-03-26T14:33:59.001400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(10, 5))\nax = sns.histplot(data=cust, x='age', bins=cust['age'].nunique(), hue='Active', palette='gist_ncar', stat='percent')\nax.set_xlabel('CUSTOMERS AGE DISTRIBUTION')\n\nfor spine in ['bottom', 'left']:\n    ax.spines[spine].set_visible(True)\n    ax.spines[spine].set_linewidth(2)\n    ax.spines[spine].set_edgecolor('grey')\n\nax.yaxis.set_major_formatter(mtick.PercentFormatter())\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:33:59.003568Z","iopub.execute_input":"2022-03-26T14:33:59.003825Z","iopub.status.idle":"2022-03-26T14:34:00.152758Z","shell.execute_reply.started":"2022-03-26T14:33:59.003789Z","shell.execute_reply":"2022-03-26T14:34:00.151902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"active_age_ratio = cust.groupby('age')['Active'].value_counts(normalize=True).mul(100)\nactive_age_ratio = active_age_ratio.rename('Active_ratio', inplace=True).reset_index()\nactive_age_ratio = active_age_ratio[active_age_ratio['Active'] == 1]\nactive_age_ratio['Active'] = active_age_ratio['Active'].astype(int)\nactive_age_ratio['age'] = active_age_ratio['age'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:00.154207Z","iopub.execute_input":"2022-03-26T14:34:00.154441Z","iopub.status.idle":"2022-03-26T14:34:00.409725Z","shell.execute_reply.started":"2022-03-26T14:34:00.154412Z","shell.execute_reply":"2022-03-26T14:34:00.408817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(16, 8))\nsns.barplot(data=active_age_ratio , x='age', y='Active_ratio')\n\nfor label in ax.xaxis.get_ticklabels()[::2]:\n    label.set_visible(False)\n    \nfor spine in ['bottom', 'left']:\n    ax.spines[spine].set_visible(True)\n    ax.spines[spine].set_linewidth(2)\n    ax.spines[spine].set_edgecolor('grey')\n\nax.yaxis.set_major_formatter(mtick.PercentFormatter())\nax.set_title('SHARE OF ACTIVE USERS PER AGE', color='turquoise', fontsize=12, weight='bold')\n\nplt.show()    ","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:00.410990Z","iopub.execute_input":"2022-03-26T14:34:00.411191Z","iopub.status.idle":"2022-03-26T14:34:01.258089Z","shell.execute_reply.started":"2022-03-26T14:34:00.411165Z","shell.execute_reply":"2022-03-26T14:34:01.257021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mpl.rcParams.update(mpl.rcParamsDefault)\n\ntrans_dtypes = trans.dtypes.value_counts()\ntrans_dtypes","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:01.259609Z","iopub.execute_input":"2022-03-26T14:34:01.260190Z","iopub.status.idle":"2022-03-26T14:34:01.270691Z","shell.execute_reply.started":"2022-03-26T14:34:01.260149Z","shell.execute_reply":"2022-03-26T14:34:01.269687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:01.272388Z","iopub.execute_input":"2022-03-26T14:34:01.273185Z","iopub.status.idle":"2022-03-26T14:34:01.287537Z","shell.execute_reply.started":"2022-03-26T14:34:01.273137Z","shell.execute_reply":"2022-03-26T14:34:01.286281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = trans\nfig = plt.figure(figsize=(5, 2))\n\nax_0 = fig.add_subplot(1, 1, 1)\nax_0.text(1.0,\n          1,\n          'KEY FIGURES',\n          color='darkolivegreen',\n          fontsize=20, \n          fontweight='bold',\n          fontfamily='monospace',\n          ha='center')\n\nax_0.text(0,\n          0.4,\n          f'{data.shape[0]:,d}',\n          color='lime',\n          fontsize=18, \n          fontweight='bold',\n          fontfamily='monospace',\n          ha='center')\nax_0.text(0,\n          0.001,\n          'DATASET ROWS NUMBER',\n          color='dimgrey',\n          fontsize=10, \n          fontweight='light',\n          fontfamily='monospace',\n          ha='center')\n\nax_0.text(0.6,\n          0.4,\n          f'{data.shape[1]}',\n          color='lime',\n          fontsize=18, \n          fontweight='bold',\n          fontfamily='monospace',\n          ha='center')\nax_0.text(0.6,\n          0.001,\n          'DATASET FEATURES NUMBER',\n          color='dimgrey',\n          fontsize=10, \n          fontweight='light',\n          fontfamily='monospace',\n          ha='center')\n\nax_0.text(1.2,\n          0.4,\n          f'{trans_dtypes[0]}',\n          color='lime',\n          fontsize=18, \n          fontweight='bold',\n          fontfamily='monospace',\n          ha='center')\nax_0.text(1.2,\n          0.001,\n          'DATASET TEXT COLUMNS NUMBER',\n          color='dimgrey',\n          fontsize=10, \n          fontweight='light',\n          fontfamily='monospace',\n          ha='center')\n\nax_0.text(1.9,\n          0.4,\n          f'{trans_dtypes[1]}',\n          color='lime',\n          fontsize=18, \n          fontweight='bold',\n          fontfamily='monospace',\n          ha='center')\nax_0.text(1.9,\n          0.001,\n          'DATASET NUMERIC COLUMNS NUMBER',\n          color='dimgrey',\n          fontsize=10, \n          fontweight='light',\n          fontfamily='monospace',\n          ha='center')\n\nax_0.set_xticklabels('')\nax_0.tick_params(axis='x', length=1)\nax_0.tick_params(axis='y', length=1)\nax_0.set_yticklabels('')\n\nfor spine in ['top', 'right', 'bottom', 'left']:\n    ax_0.spines[spine].set_visible(False)\n    \nfig.patch.set_linewidth(5)\nfig.patch.set_edgecolor('pink')\nfig.patch.set_facecolor('mistyrose')\n\nax_0.set_facecolor('mistyrose')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:01.289007Z","iopub.execute_input":"2022-03-26T14:34:01.289254Z","iopub.status.idle":"2022-03-26T14:34:01.429988Z","shell.execute_reply.started":"2022-03-26T14:34:01.289224Z","shell.execute_reply":"2022-03-26T14:34:01.428854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:01.431919Z","iopub.execute_input":"2022-03-26T14:34:01.433024Z","iopub.status.idle":"2022-03-26T14:34:08.371691Z","shell.execute_reply.started":"2022-03-26T14:34:01.432961Z","shell.execute_reply":"2022-03-26T14:34:08.370813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style('darkgrid', {'axes.facecolor': '.3'})\nfig, ax = plt.subplots(figsize=(10, 5), facecolor='#ff9999')\nax = sns.histplot(data=trans, x='price', bins=50, color='red', stat='percent')\nax.set_xlabel('PRICE DISTRIBUTION')\n\nfor spine in ['bottom', 'left']:\n    ax.spines[spine].set_visible(True)\n    ax.spines[spine].set_linewidth(2)\n    ax.spines[spine].set_color('pink')\n    \nax.yaxis.set_major_formatter(mtick.PercentFormatter())\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:08.372834Z","iopub.execute_input":"2022-03-26T14:34:08.373079Z","iopub.status.idle":"2022-03-26T14:34:18.117284Z","shell.execute_reply.started":"2022-03-26T14:34:08.373050Z","shell.execute_reply":"2022-03-26T14:34:18.116487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(10, 5), facecolor='#a6fff2')\ndata = trans[trans['price'] < 0.1]\n\nax = sns.histplot(data=data, x='price', bins=20, color='#00ffc3', stat='percent')\nax.set_xlabel('PRICE DUSTRIBUTION UNDER 0.1')\n\nfor spine in ['bottom', 'left']:\n    ax.spines[spine].set_visible(True)\n    ax.spines[spine].set_linewidth(2)\n    ax.spines[spine].set_color('lime')\n    \nax.yaxis.set_major_formatter(mtick.PercentFormatter())\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:18.118436Z","iopub.execute_input":"2022-03-26T14:34:18.118672Z","iopub.status.idle":"2022-03-26T14:34:29.362985Z","shell.execute_reply.started":"2022-03-26T14:34:18.118643Z","shell.execute_reply":"2022-03-26T14:34:29.361986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans['t_dat'] = pd.to_datetime(trans['t_dat'])","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:29.364104Z","iopub.execute_input":"2022-03-26T14:34:29.364335Z","iopub.status.idle":"2022-03-26T14:34:35.749626Z","shell.execute_reply.started":"2022-03-26T14:34:29.364304Z","shell.execute_reply":"2022-03-26T14:34:35.748733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"start = trans['t_dat'].min()\nend = trans['t_dat'].max()\nprint(f'DATE DATA RANGES FROM {start.date()} TO {end.date()}')","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:35.751123Z","iopub.execute_input":"2022-03-26T14:34:35.751477Z","iopub.status.idle":"2022-03-26T14:34:35.963021Z","shell.execute_reply.started":"2022-03-26T14:34:35.751432Z","shell.execute_reply":"2022-03-26T14:34:35.961367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:35.964254Z","iopub.execute_input":"2022-03-26T14:34:35.964481Z","iopub.status.idle":"2022-03-26T14:34:35.981921Z","shell.execute_reply.started":"2022-03-26T14:34:35.964455Z","shell.execute_reply":"2022-03-26T14:34:35.981282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_per_day = trans.groupby(['t_dat'], as_index=False).count()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:35.983266Z","iopub.execute_input":"2022-03-26T14:34:35.983787Z","iopub.status.idle":"2022-03-26T14:34:41.127052Z","shell.execute_reply.started":"2022-03-26T14:34:35.983753Z","shell.execute_reply":"2022-03-26T14:34:41.126085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_per_day","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:41.128343Z","iopub.execute_input":"2022-03-26T14:34:41.128599Z","iopub.status.idle":"2022-03-26T14:34:41.142573Z","shell.execute_reply.started":"2022-03-26T14:34:41.128568Z","shell.execute_reply":"2022-03-26T14:34:41.141952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_id_max = trans_per_day['customer_id'].max()\ntrans_id_max","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:41.143665Z","iopub.execute_input":"2022-03-26T14:34:41.144399Z","iopub.status.idle":"2022-03-26T14:34:41.156858Z","shell.execute_reply.started":"2022-03-26T14:34:41.144344Z","shell.execute_reply":"2022-03-26T14:34:41.156033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_id_max_date = trans_per_day[trans_per_day['customer_id'] == trans_id_max]['t_dat']\ntrans_id_max_date","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:41.158133Z","iopub.execute_input":"2022-03-26T14:34:41.158382Z","iopub.status.idle":"2022-03-26T14:34:41.174641Z","shell.execute_reply.started":"2022-03-26T14:34:41.158353Z","shell.execute_reply":"2022-03-26T14:34:41.173985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_id_max_date.iloc[0].date()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:41.176069Z","iopub.execute_input":"2022-03-26T14:34:41.176525Z","iopub.status.idle":"2022-03-26T14:34:41.186785Z","shell.execute_reply.started":"2022-03-26T14:34:41.176492Z","shell.execute_reply":"2022-03-26T14:34:41.185802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_id_max_date + pd.DateOffset(days=5)","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:41.188868Z","iopub.execute_input":"2022-03-26T14:34:41.189276Z","iopub.status.idle":"2022-03-26T14:34:41.200488Z","shell.execute_reply.started":"2022-03-26T14:34:41.189232Z","shell.execute_reply":"2022-03-26T14:34:41.199599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_id_max - 4000","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:41.201999Z","iopub.execute_input":"2022-03-26T14:34:41.202762Z","iopub.status.idle":"2022-03-26T14:34:41.212515Z","shell.execute_reply.started":"2022-03-26T14:34:41.202669Z","shell.execute_reply":"2022-03-26T14:34:41.211500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(16, 8))\nsns.lineplot(data=trans_per_day, x='t_dat', y='customer_id', color='deeppink')\n\nax.set_xlabel('DATE')\nax.set_ylabel('TRANSACTIONS NUMBER')\n\nax.axvline(x=dt.datetime(2019, 1, 1), c='lime')\nax.axvline(x=dt.datetime(2020, 1, 1), c='lime')\n\ntrans_id_max = trans_per_day['customer_id'].max()\ntrans_id_max_date = trans_per_day[trans_per_day['customer_id'] == trans_id_max]['t_dat']\n\nax.scatter(trans_id_max_date, trans_id_max, c='yellow')\nax.text(trans_id_max_date + pd.DateOffset(days=5),\n        trans_id_max - 4000,\n        f'{trans_id_max_date.iloc[0].date()}\\n{trans_id_max}',\n        color='silver')\n\ntrans_id_min = trans_per_day['customer_id'].min()\ntrans_id_min_date = trans_per_day[trans_per_day['customer_id'] == trans_id_min]['t_dat']\n\nax.scatter(trans_id_min_date, trans_id_min, c='yellow')\nax.text(trans_id_min_date + pd.DateOffset(days=5),\n        trans_id_min - 4000,\n        f'{trans_id_min_date.iloc[0].date()}\\n{trans_id_min}',\n        color='silver')\n\nax.set_xlim(trans['t_dat'].min(), trans['t_dat'].max())\nfor spine in ['bottom', 'left']:\n    ax.spines[spine].set_visible(True)\n    ax.spines[spine].set_linewidth(2)\n    ax.spines[spine].set_color('crimson')\n    \nax.yaxis.set_major_formatter(mtick.PercentFormatter())\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:41.213791Z","iopub.execute_input":"2022-03-26T14:34:41.214163Z","iopub.status.idle":"2022-03-26T14:34:41.967454Z","shell.execute_reply.started":"2022-03-26T14:34:41.214132Z","shell.execute_reply":"2022-03-26T14:34:41.966179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_grp_month = trans.groupby('t_dat').size()\ntrans_grp_month","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:41.969249Z","iopub.execute_input":"2022-03-26T14:34:41.969617Z","iopub.status.idle":"2022-03-26T14:34:42.647803Z","shell.execute_reply.started":"2022-03-26T14:34:41.969552Z","shell.execute_reply":"2022-03-26T14:34:42.647016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_grp_month = trans_grp_month.rename('no_transactions')\ntrans_grp_month","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:42.649025Z","iopub.execute_input":"2022-03-26T14:34:42.649276Z","iopub.status.idle":"2022-03-26T14:34:42.657778Z","shell.execute_reply.started":"2022-03-26T14:34:42.649245Z","shell.execute_reply":"2022-03-26T14:34:42.656937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_grp_month = trans_grp_month.reset_index()\ntrans_grp_month","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:42.659203Z","iopub.execute_input":"2022-03-26T14:34:42.659711Z","iopub.status.idle":"2022-03-26T14:34:42.676590Z","shell.execute_reply.started":"2022-03-26T14:34:42.659668Z","shell.execute_reply":"2022-03-26T14:34:42.675666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_grp_month = trans.groupby('t_dat').size().rename('no_transactions').reset_index()\ntrans_grp_month","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:42.677958Z","iopub.execute_input":"2022-03-26T14:34:42.678270Z","iopub.status.idle":"2022-03-26T14:34:43.366892Z","shell.execute_reply.started":"2022-03-26T14:34:42.678239Z","shell.execute_reply":"2022-03-26T14:34:43.365960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_grp_month['year_month'] = trans_grp_month['t_dat'].dt.to_period('M')\ntrans_grp_month","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:43.368306Z","iopub.execute_input":"2022-03-26T14:34:43.368539Z","iopub.status.idle":"2022-03-26T14:34:43.384994Z","shell.execute_reply.started":"2022-03-26T14:34:43.368507Z","shell.execute_reply":"2022-03-26T14:34:43.384358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_style('darkgrid', {'axes.facecolor': '.7'})\n\nfig, ax = plt.subplots(figsize=(16, 8))\nax = sns.boxplot(data=trans_grp_month, x='year_month', y='no_transactions', palette='gist_ncar')\nplt.xticks(rotation=90)\n\nfor spine in ['bottom', 'left']:\n    ax.spines[spine].set_visible(True)\n    ax.spines[spine].set_linewidth(2)\n    ax.spines[spine].set_color('crimson')\n    \nax.set_xlabel('YEAR-MONTH')\nax.set_ylabel('TRANSACTIONS NUMBER')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:43.386196Z","iopub.execute_input":"2022-03-26T14:34:43.387011Z","iopub.status.idle":"2022-03-26T14:34:44.104819Z","shell.execute_reply.started":"2022-03-26T14:34:43.386959Z","shell.execute_reply":"2022-03-26T14:34:44.103928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_by_customer = trans.groupby(['customer_id'], as_index=False).count()\ntrans_by_customer","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:44.106090Z","iopub.execute_input":"2022-03-26T14:34:44.106413Z","iopub.status.idle":"2022-03-26T14:34:59.102314Z","shell.execute_reply.started":"2022-03-26T14:34:44.106377Z","shell.execute_reply":"2022-03-26T14:34:59.101646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_by_customer = trans.groupby(['customer_id'], as_index=False).size()\ntrans_by_customer","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:34:59.103268Z","iopub.execute_input":"2022-03-26T14:34:59.104073Z","iopub.status.idle":"2022-03-26T14:35:12.900235Z","shell.execute_reply.started":"2022-03-26T14:34:59.104034Z","shell.execute_reply":"2022-03-26T14:35:12.899391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(10, 5))\nax = sns.histplot(data=trans_by_customer, x='size', bins=50, color='yellow',  stat='percent')\nax.set_xlabel('TOTAL TRANSACTIONS PER CUSTOMER DISTRIBUTION')\n\nfor spine in ['bottom', 'left']:\n    ax.spines[spine].set_visible(True)\n    ax.spines[spine].set_linewidth(2)\n    ax.spines[spine].set_color('goldenrod')\n    \nax.yaxis.set_major_formatter(mtick.PercentFormatter())\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:35:12.901653Z","iopub.execute_input":"2022-03-26T14:35:12.901890Z","iopub.status.idle":"2022-03-26T14:35:13.415279Z","shell.execute_reply.started":"2022-03-26T14:35:12.901849Z","shell.execute_reply":"2022-03-26T14:35:13.414352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_by_customer_less50 = trans_by_customer[trans_by_customer['size'] < 50]\ntrans_by_customer_less50","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:35:13.416735Z","iopub.execute_input":"2022-03-26T14:35:13.417246Z","iopub.status.idle":"2022-03-26T14:35:13.513388Z","shell.execute_reply.started":"2022-03-26T14:35:13.417196Z","shell.execute_reply":"2022-03-26T14:35:13.512451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(10, 5))\nax = sns.histplot(data=trans_by_customer_less50, x='size', bins=50, color='darkblue',  stat='percent')\nax.set_xlabel('TOTAL TRANSACTIONS PER CUSTOMER LESS THAN 50 DISTRIBUTION')\n\nfor spine in ['bottom', 'left']:\n    ax.spines[spine].set_visible(True)\n    ax.spines[spine].set_linewidth(2)\n    ax.spines[spine].set_color('cyan')\n    \nax.yaxis.set_major_formatter(mtick.PercentFormatter())\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:35:13.514866Z","iopub.execute_input":"2022-03-26T14:35:13.515235Z","iopub.status.idle":"2022-03-26T14:35:14.319605Z","shell.execute_reply.started":"2022-03-26T14:35:13.515177Z","shell.execute_reply":"2022-03-26T14:35:14.318967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(5, 5))\nexplode = (0, 0.1)\n\ncolors = sns.color_palette('rainbow')\nax.pie(trans['sales_channel_id'].value_counts(),\n       explode=explode,\n       labels=['1', '2'],\n       autopct='%1.1f%%',\n       shadow=True,\n       startangle=90,\n       colors=colors)\nax.axis('equal')\nax.set_title('SALE CHANNEL')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:35:14.320927Z","iopub.execute_input":"2022-03-26T14:35:14.321599Z","iopub.status.idle":"2022-03-26T14:35:14.621790Z","shell.execute_reply.started":"2022-03-26T14:35:14.321559Z","shell.execute_reply":"2022-03-26T14:35:14.620671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:35:14.623480Z","iopub.execute_input":"2022-03-26T14:35:14.623955Z","iopub.status.idle":"2022-03-26T14:35:14.651226Z","shell.execute_reply.started":"2022-03-26T14:35:14.623903Z","shell.execute_reply":"2022-03-26T14:35:14.649950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans['year_month'] = trans['t_dat'].dt.to_period('M')\ntrans","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:35:14.653123Z","iopub.execute_input":"2022-03-26T14:35:14.653735Z","iopub.status.idle":"2022-03-26T14:35:17.924925Z","shell.execute_reply.started":"2022-03-26T14:35:14.653677Z","shell.execute_reply":"2022-03-26T14:35:17.923965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_grouped = trans.groupby(['year_month', 'article_id']).size().rename('total_per_article')\ntrans_grouped","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:35:17.926218Z","iopub.execute_input":"2022-03-26T14:35:17.926479Z","iopub.status.idle":"2022-03-26T14:35:21.012934Z","shell.execute_reply.started":"2022-03-26T14:35:17.926449Z","shell.execute_reply":"2022-03-26T14:35:21.011964Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_grouped = trans.groupby(['year_month', 'article_id']).size().rename('total_per_article').to_frame()\ntrans_grouped","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:35:21.014711Z","iopub.execute_input":"2022-03-26T14:35:21.015344Z","iopub.status.idle":"2022-03-26T14:35:24.152267Z","shell.execute_reply.started":"2022-03-26T14:35:21.015283Z","shell.execute_reply":"2022-03-26T14:35:24.151186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_grouped.reset_index(inplace=True)\ntrans_grouped","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:35:24.153583Z","iopub.execute_input":"2022-03-26T14:35:24.153843Z","iopub.status.idle":"2022-03-26T14:35:24.181652Z","shell.execute_reply.started":"2022-03-26T14:35:24.153816Z","shell.execute_reply":"2022-03-26T14:35:24.180625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"art_trans = pd.merge(art[['article_id', 'index_name']], trans_grouped, on='article_id')\nart_trans","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:35:24.183510Z","iopub.execute_input":"2022-03-26T14:35:24.183985Z","iopub.status.idle":"2022-03-26T14:35:24.337359Z","shell.execute_reply.started":"2022-03-26T14:35:24.183934Z","shell.execute_reply":"2022-03-26T14:35:24.336249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"art_trans = art_trans.groupby(['year_month', 'index_name'])['total_per_article'].sum().to_frame()\nart_trans","metadata":{"execution":{"iopub.status.busy":"2022-03-26T14:35:24.338687Z","iopub.execute_input":"2022-03-26T14:35:24.338963Z","iopub.status.idle":"2022-03-26T14:35:24.448186Z","shell.execute_reply.started":"2022-03-26T14:35:24.338930Z","shell.execute_reply":"2022-03-26T14:35:24.447249Z"},"trusted":true},"execution_count":null,"outputs":[]}]}