{"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":"# Loading libraries and data","metadata":{}},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\n#import numpy as np # linear algebra\n#import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\n#import os\n#for dirname, _, filenames in os.walk('/kaggle/input'):\n#    for filename in filenames:\n#        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-21T12:07:34.416436Z","iopub.execute_input":"2022-03-21T12:07:34.416953Z","iopub.status.idle":"2022-03-21T12:07:34.422174Z","shell.execute_reply.started":"2022-03-21T12:07:34.416871Z","shell.execute_reply":"2022-03-21T12:07:34.421205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport numpy as np # linear algebra\nimport os\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly.express as px\nfrom os import listdir\nfrom os.path import isfile, join\n\nfrom termcolor import colored\nfrom IPython.display import HTML\n\nimport warnings\npd.set_option('display.max_rows', None)\npd.set_option('display.max_columns', None)\npd.set_option('float_format', '{:f}'.format)\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:07:34.426637Z","iopub.execute_input":"2022-03-21T12:07:34.427101Z","iopub.status.idle":"2022-03-21T12:07:37.312538Z","shell.execute_reply.started":"2022-03-21T12:07:34.427060Z","shell.execute_reply":"2022-03-21T12:07:37.311302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/articles.csv\")\ncustomers = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/customers.csv\")\ntransactions = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:07:37.314485Z","iopub.execute_input":"2022-03-21T12:07:37.314755Z","iopub.status.idle":"2022-03-21T12:09:01.512924Z","shell.execute_reply.started":"2022-03-21T12:07:37.314724Z","shell.execute_reply":"2022-03-21T12:09:01.511089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#images_dir = '../input/h-and-m-personalized-fashion-recommendations/images'\n#cat_images = [f for f in listdir(images_dir)]","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:01.515686Z","iopub.execute_input":"2022-03-21T12:09:01.516064Z","iopub.status.idle":"2022-03-21T12:09:01.523511Z","shell.execute_reply.started":"2022-03-21T12:09:01.516026Z","shell.execute_reply":"2022-03-21T12:09:01.522000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Basic Information on datasets","metadata":{}},{"cell_type":"code","source":"print(f\"Number of observations in ARTICLES: {colored(articles.shape, 'yellow')}\")\nprint(f\"Number of observations in CUSTOMERS: {colored(customers.shape, 'yellow')}\")\nprint(f\"Number of observations in TRANSACTIONS: {colored(transactions.shape, 'yellow')}\")","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:01.524968Z","iopub.execute_input":"2022-03-21T12:09:01.525230Z","iopub.status.idle":"2022-03-21T12:09:01.541301Z","shell.execute_reply.started":"2022-03-21T12:09:01.525201Z","shell.execute_reply":"2022-03-21T12:09:01.540216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# This code was borrowed from https://www.kaggle.com/ishandutta/v7-shopee-indepth-eda-one-stop-for-all-your-needs\ndef getImagePaths(path):\n    \"\"\"\n    Function to Combine Directory Path with individual Image Paths\n    \n    parameters: path(string) - Path of directory\n    returns: image_names(string) - Full Image Path\n    \"\"\"\n    image_names = []\n    for dirname, _, filenames in os.walk(path):\n        for filename in filenames:\n            fullpath = os.path.join(dirname, filename)\n            image_names.append(fullpath)\n    return image_names\n\ndef display_multiple_img(images_paths, rows, cols):\n    \"\"\"\n    Function to Display Images from Dataset.\n    \n    parameters: images_path(string) - Paths of Images to be displayed\n                rows(int) - No. of Rows in Output\n                cols(int) - No. of Columns in Output\n    \"\"\"\n    figure, ax = plt.subplots(nrows=rows,ncols=cols,figsize=(16,8) )\n    for ind,image_path in enumerate(images_paths):\n        image=cv2.imread(image_path)\n        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) \n        try:\n            ax.ravel()[ind].imshow(image)\n            ax.ravel()[ind].set_axis_off()\n        except:\n            continue;\n    plt.tight_layout()\n    plt.show()\n\ndef plot_distribution(x, data, title):\n        fig = px.histogram(\n        data, \n        x = x,\n        width = 800,\n        height = 500,\n        title = title\n        )\n\n        fig.show()\ndef disply_multiple_img_ids(idx, rows, cols):\n    figure, ax = plt.subplots(nrows=rows,ncols=cols,figsize=(16,8))\n    for ind, im_id in enumerate(idx):\n\n        image_path = f'{images_dir}/0{str(im_id)[:2]}/0{im_id}.jpg'\n        \n        image=cv2.imread(image_path)\n        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) \n        try:\n            ax.ravel()[ind].imshow(image)\n            ax.ravel()[ind].set_axis_off()\n        except:\n            continue;\n    plt.tight_layout()\n    plt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:01.545561Z","iopub.execute_input":"2022-03-21T12:09:01.546175Z","iopub.status.idle":"2022-03-21T12:09:01.563607Z","shell.execute_reply.started":"2022-03-21T12:09:01.546117Z","shell.execute_reply":"2022-03-21T12:09:01.562518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#images_path = getImagePaths(images_dir)","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:01.566038Z","iopub.execute_input":"2022-03-21T12:09:01.566769Z","iopub.status.idle":"2022-03-21T12:09:01.583733Z","shell.execute_reply.started":"2022-03-21T12:09:01.566719Z","shell.execute_reply":"2022-03-21T12:09:01.582658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#print(f\"There are {colored(len(images_path), 'yellow')} number of images in dataset\")","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:01.585639Z","iopub.execute_input":"2022-03-21T12:09:01.586220Z","iopub.status.idle":"2022-03-21T12:09:01.597185Z","shell.execute_reply.started":"2022-03-21T12:09:01.586176Z","shell.execute_reply":"2022-03-21T12:09:01.596349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#display_multiple_img(images_path[50:100], 5, 5)","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:01.599030Z","iopub.execute_input":"2022-03-21T12:09:01.599595Z","iopub.status.idle":"2022-03-21T12:09:01.617258Z","shell.execute_reply.started":"2022-03-21T12:09:01.599555Z","shell.execute_reply":"2022-03-21T12:09:01.616309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# QUICK LOOK INTO DATA","metadata":{}},{"cell_type":"markdown","source":"## A. ARTICLES","metadata":{}},{"cell_type":"markdown","source":"**<span style=\"color:#023e8a;\"> This table contains all h&m articles with details such as a type of product, a color, a product group and other features.</span>**  \n**<span style=\"color:#023e8a;\"> Article data description: </span>**\n  \n- 105542 rows and 25 columns  \n- No nulls apart from detail_desc  \n- 11 int and 14 obj types are present  \n> `article_id` **<span style=\"color:#023e8a;\">: A unique identifier of every article.</span>**  \n>  - The primary column  \n  \n> `product_code`, `prod_name` **<span style=\"color:#023e8a;\">: A unique identifier of every product and its name (not the same).</span>** >  - 47224 unique product_code  \n>  - product_code and article id are highly correlated  \n>  - 45875 uniqe prod_name. **Different from product_code**. Which one to use?  \n>  - No specific dominant levels in prod_name  \n  \n> `product_type`, `product_type_name` **<span style=\"color:#023e8a;\">: The group of product_code and its name</span>**  \n>  - 132 unique product types, but 131 unique product names  \n>  - dominant levels are present in both. first 8 form ~80% of total data  \n  \n> 'product_group_name' : 19 unique values. highly dominant levels are present.  \n  \n> `graphical_appearance_no`, `graphical_appearance_name` **<span style=\"color:#023e8a;\">: The group of graphics and its name</span>**  \n>  - both has 30 unique values. 1-1 mapping  \n>  - highly dominant levels present  \n  \n> `colour_group_code`, `colour_group_name` **<span style=\"color:#023e8a;\">: The group of color and its name</span>**  \n>  - both 50 unique values. 1-1 mapping  \n>  - mildly dominant levels  \n  \n> `perceived_colour_value_id`, `perceived_colour_value_name`, `perceived_colour_master_id`, `perceived_colour_master_name` **<span style=\"color:#023e8a;\">: The added color info</span>**    \n>  - only 8 levels in both\n  \n> `department_no`, `department_name`: **<span style=\"color:#023e8a;\">: A unique identifier of every dep and its name</span>**  \n>  - 299 unique department_no, 250 unique department_name. **Not matching**  \n>  - no dominant levels.   \n  \n> `index_code`, `index_name`: **<span style=\"color:#023e8a;\">: A unique identifier of every index and its name</span>**  \n>  - 10 levels in both 1-1 mapping.  \n>  - obviously dominant  \n  \n> `index_group_no`, `index_group_name`: **<span style=\"color:#023e8a;\">: A group of indeces and its name</span>**  \n>  - 5 levels in both  \n>  - obviously dominant  \n  \n> `section_no`, `section_name`: **<span style=\"color:#023e8a;\">: A unique identifier of every section and its name</span>**  \n>  - 57 in section no, 56 in section name . **Not one-one matching**  \n>  - Non dominant  \n  \n> `garment_group_no`, `garment_group_name`: **<span style=\"color:#023e8a;\">: A unique identifier of every garment and its name</span>**  \n>  - 21 in both levels. 1-1 mapping  \n>  - some dominant levels  \n  \n> `detail_desc`: **<span style=\"color:#023e8a;\">: Details</span>**  \n>  - All unique descriptions. many are nulls. Not sure how helpful it'll be","metadata":{}},{"cell_type":"code","source":"articles.shape","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:01.618614Z","iopub.execute_input":"2022-03-21T12:09:01.619531Z","iopub.status.idle":"2022-03-21T12:09:01.635730Z","shell.execute_reply.started":"2022-03-21T12:09:01.619486Z","shell.execute_reply":"2022-03-21T12:09:01.634759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.info()","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:01.637514Z","iopub.execute_input":"2022-03-21T12:09:01.638074Z","iopub.status.idle":"2022-03-21T12:09:01.869927Z","shell.execute_reply.started":"2022-03-21T12:09:01.638037Z","shell.execute_reply":"2022-03-21T12:09:01.868818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.describe()","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:01.871830Z","iopub.execute_input":"2022-03-21T12:09:01.872245Z","iopub.status.idle":"2022-03-21T12:09:01.971047Z","shell.execute_reply.started":"2022-03-21T12:09:01.872190Z","shell.execute_reply":"2022-03-21T12:09:01.969888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:01.972658Z","iopub.execute_input":"2022-03-21T12:09:01.973367Z","iopub.status.idle":"2022-03-21T12:09:02.143889Z","shell.execute_reply.started":"2022-03-21T12:09:01.973324Z","shell.execute_reply":"2022-03-21T12:09:02.142946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"detail_desc is the only column with nulls","metadata":{}},{"cell_type":"code","source":"articles.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:02.147060Z","iopub.execute_input":"2022-03-21T12:09:02.147479Z","iopub.status.idle":"2022-03-21T12:09:02.339057Z","shell.execute_reply.started":"2022-03-21T12:09:02.147443Z","shell.execute_reply":"2022-03-21T12:09:02.338274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corr = articles.corr()\nplt.figure(figsize=(16,6))\nsns.heatmap(corr,xticklabels=corr.columns,yticklabels=corr.columns,cmap='Greens',annot=True)","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:02.340847Z","iopub.execute_input":"2022-03-21T12:09:02.341371Z","iopub.status.idle":"2022-03-21T12:09:03.723103Z","shell.execute_reply.started":"2022-03-21T12:09:02.341336Z","shell.execute_reply":"2022-03-21T12:09:03.722266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"index_group_no and section_no has correlation with department_no\ngarment_group_no has correlation with sectoin_no\nrest all seems independent","metadata":{}},{"cell_type":"markdown","source":"## Subset only columns of interest","metadata":{}},{"cell_type":"code","source":"articles_sub = articles[['article_id','prod_name','product_type_name','product_group_name','graphical_appearance_name','colour_group_name'\n                         ,'perceived_colour_value_name','perceived_colour_master_name','department_name','index_name','index_group_name'\n                         ,'section_name','garment_group_name','detail_desc']]\narticles_sub.shape","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:03.724624Z","iopub.execute_input":"2022-03-21T12:09:03.725159Z","iopub.status.idle":"2022-03-21T12:09:03.749731Z","shell.execute_reply.started":"2022-03-21T12:09:03.725120Z","shell.execute_reply":"2022-03-21T12:09:03.748746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"conda install -c conda-forge dython","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:09:03.752432Z","iopub.execute_input":"2022-03-21T12:09:03.752799Z","iopub.status.idle":"2022-03-21T12:10:08.686520Z","shell.execute_reply.started":"2022-03-21T12:09:03.752750Z","shell.execute_reply":"2022-03-21T12:10:08.685337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from dython.nominal import theils_u","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:10:08.688812Z","iopub.execute_input":"2022-03-21T12:10:08.689091Z","iopub.status.idle":"2022-03-21T12:10:09.309330Z","shell.execute_reply.started":"2022-03-21T12:10:08.689059Z","shell.execute_reply":"2022-03-21T12:10:09.308278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corr = pd.DataFrame(columns = ['columns'] + list(articles_sub.columns))\ncorr['columns'] = articles_sub.columns\n\nfor i in range(1,corr.shape[1]):\n    for j in range(corr.shape[0]):\n        x = corr.columns[i]\n        y = corr.iloc[j,0]\n        corr.iloc[j,i] = theils_u(articles_sub[x],articles_sub[y])\n        \n","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:10:09.310926Z","iopub.execute_input":"2022-03-21T12:10:09.311302Z","iopub.status.idle":"2022-03-21T12:13:05.027863Z","shell.execute_reply.started":"2022-03-21T12:10:09.311255Z","shell.execute_reply":"2022-03-21T12:13:05.026577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corr","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:13:05.030408Z","iopub.execute_input":"2022-03-21T12:13:05.030929Z","iopub.status.idle":"2022-03-21T12:13:05.056042Z","shell.execute_reply.started":"2022-03-21T12:13:05.030893Z","shell.execute_reply":"2022-03-21T12:13:05.054622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_sub.dtypes","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:28:10.030220Z","iopub.execute_input":"2022-03-21T12:28:10.030719Z","iopub.status.idle":"2022-03-21T12:28:10.041694Z","shell.execute_reply.started":"2022-03-21T12:28:10.030684Z","shell.execute_reply":"2022-03-21T12:28:10.040680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_sub.columns","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:28:11.615429Z","iopub.execute_input":"2022-03-21T12:28:11.616665Z","iopub.status.idle":"2022-03-21T12:28:11.624779Z","shell.execute_reply.started":"2022-03-21T12:28:11.616595Z","shell.execute_reply":"2022-03-21T12:28:11.624060Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Create non-overlapping information from all columns","metadata":{}},{"cell_type":"code","source":"import re\n\ns = re.sub('[^0-9a-zA-Z]+', '*', s)\narticles_sub.replace(to_replace ='[nN]ew', value = 'New_', regex = True)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = ['prod_name', 'product_type_name', 'product_group_name',\n       'graphical_appearance_name', 'colour_group_name',\n       'perceived_colour_value_name', 'perceived_colour_master_name',\n       'department_name', 'index_name', 'index_group_name', 'section_name',\n       'garment_group_name', 'detail_desc']\narticles_sub['combined'] = articles_sub[cols].apply(lambda row: '_'.join(row.values.astype(str)), axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:28:19.433291Z","iopub.execute_input":"2022-03-21T12:28:19.433754Z","iopub.status.idle":"2022-03-21T12:28:22.604620Z","shell.execute_reply.started":"2022-03-21T12:28:19.433712Z","shell.execute_reply":"2022-03-21T12:28:22.603371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_sub.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-21T12:28:28.543991Z","iopub.execute_input":"2022-03-21T12:28:28.544502Z","iopub.status.idle":"2022-03-21T12:28:28.564783Z","shell.execute_reply.started":"2022-03-21T12:28:28.544447Z","shell.execute_reply":"2022-03-21T12:28:28.563503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Understanding each variable","metadata":{}},{"cell_type":"code","source":"def distribution_plot(data,variable):\n    data = data[[variable]]\n    \n    figure,axis = plt.subplots(1,1,figsize=(10,5))\n    s = data.value_counts()\n    s_len = s/len(data.index)*100\n    \n    res = pd.concat([s, s_len], axis=1).reset_index().set_axis(['LEVELS','COUNT', 'PERCENTAGE'], axis=1, inplace=False).sort_values('PERCENTAGE',ascending = False)\n    res.drop('COUNT',axis=1,inplace=True)\n    if res.shape[0] >=9:\n        res.iloc[8] = res.iloc[8:].sum()\n        res = res.iloc[:9]\n        res.iat[8,0] = 'Others'\n    else:\n        None\n    \n    res.plot.bar(x='LEVELS',ax=axis)\n    axis.set_title(variable)\n    plt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in articles.columns:\n    distribution_plot(articles,i)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Customers Dataset","metadata":{}},{"cell_type":"markdown","source":"**<span style=\"color:#023e8a;\"> Customers data description: </span>**\n\n> `customer_id` **<span style=\"color:#023e8a;\">: A unique identifier of every customer</span>**  \n> `FN` **<span style=\"color:#023e8a;\">: 1 or missed </span>**  \n> `Active` **<span style=\"color:#023e8a;\">: 1 or missed</span>**  \n> `club_member_status` **<span style=\"color:#023e8a;\">: Status in club</span>**  \n> `fashion_news_frequency` **<span style=\"color:#023e8a;\">: How often H&M may send news to customer</span>**  \n> `age` **<span style=\"color:#023e8a;\">: The current age</span>**  \n> `postal_code` **<span style=\"color:#023e8a;\">: Postal code of customer</span>**  ","metadata":{}},{"cell_type":"code","source":"customers.columns","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.head(5)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.shape","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.info()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.describe()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.isnull().sum()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.nunique()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"corr = customers.corr()\nplt.figure(figsize=(16,6))\nsns.heatmap(corr,xticklabels=corr.columns,yticklabels=corr.columns,cmap='Greens',annot=True)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def distribution_plot(data,variable):\n    data = data[[variable]]\n    \n    figure,axis = plt.subplots(1,1,figsize=(10,5))\n    s = data.value_counts()\n    s_len = s/len(data.index)*100\n    \n    res = pd.concat([s, s_len], axis=1).reset_index().set_axis(['LEVELS','COUNT', 'PERCENTAGE'], axis=1, inplace=False).sort_values('PERCENTAGE',ascending = False)\n    res.drop('COUNT',axis=1,inplace=True)\n    if res.shape[0] >=9:\n        res.iloc[8] = res.iloc[8:].sum()\n        res = res.iloc[:9]\n        res.iat[8,0] = 'Others'\n    else:\n        None\n    \n    res.plot.bar(x='LEVELS',ax=axis)\n    axis.set_title(variable)\n    plt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in customers.columns[0]:\n    distribution_plot(customers,i)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers.columns[0]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customers[['customer_id']]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}