{"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":"<html>\n<head>\n</head>\n<body>\n\n   <center><h1 style=\"font-family: Brush Script MT,cursive\"> <font size=11>Inside story of what's trending on H&M! </font></h1>\n\n   <img src=\"https://media.karousell.com/media/photos/products/2020/9/25/hm_paper_bags_4_pieces_1601022393_abb9e83c_progressive.jpg\" width='100%' height='0.001%'>\n</center>\n</body>\n</html>\n\n","metadata":{}},{"cell_type":"markdown","source":"<p style='font-family: Trebuchet MS'><font size=6>Let me walk you through the journey of H&M with its customers so far!<br>\nWe begin by importing the libraries:\n</font>\n</p>","metadata":{}},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nfrom collections import Counter\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-02-11T09:02:04.227668Z","iopub.execute_input":"2022-02-11T09:02:04.228030Z","iopub.status.idle":"2022-02-11T09:02:04.250601Z","shell.execute_reply.started":"2022-02-11T09:02:04.227926Z","shell.execute_reply":"2022-02-11T09:02:04.249860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style='font-family: Trebuchet MS'><font size=6>Let's explore the dataset. Following is the article dataset which consists of various columns. This is linked to the images by the 'article_id'. Hence we will find the corresponding images of those id's and add it to the article dataset.\n</font>\n</p>","metadata":{}},{"cell_type":"code","source":"article=pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/articles.csv\")\nprint(article.columns)","metadata":{"execution":{"iopub.status.busy":"2022-02-11T09:02:04.252124Z","iopub.execute_input":"2022-02-11T09:02:04.252358Z","iopub.status.idle":"2022-02-11T09:02:05.200476Z","shell.execute_reply.started":"2022-02-11T09:02:04.252320Z","shell.execute_reply":"2022-02-11T09:02:05.199710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"images_path=[]\ni=0\nfor p in article['article_id'].tolist():\n    path= '../input/h-and-m-personalized-fashion-recommendations/images/' + '0' + str(p)[:2] + '/'+ '0' + str(p) +'.jpg'\n\n    if os.path.exists(path):\n        i+=1\n        images_path.append(path)\n    else: images_path.append(None)\nprint(f'{i} articles have corresponding images')\n\narticle['images_path']=images_path\narticle = article[['article_id', 'prod_name', 'colour_group_name', 'images_path',\n             'product_type_name', 'product_group_name', 'detail_desc']]","metadata":{"execution":{"iopub.status.busy":"2022-02-11T09:02:05.201599Z","iopub.execute_input":"2022-02-11T09:02:05.201824Z","iopub.status.idle":"2022-02-11T09:03:22.063053Z","shell.execute_reply.started":"2022-02-11T09:02:05.201796Z","shell.execute_reply":"2022-02-11T09:03:22.062245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article['prod_name'].describe()","metadata":{"execution":{"iopub.status.busy":"2022-02-11T09:03:22.065129Z","iopub.execute_input":"2022-02-11T09:03:22.065596Z","iopub.status.idle":"2022-02-11T09:03:22.122807Z","shell.execute_reply.started":"2022-02-11T09:03:22.065555Z","shell.execute_reply":"2022-02-11T09:03:22.122022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style='font-family: Trebuchet MS'><font size=6>\n    Now let's find out which colour&#127912 is trending in the H&M store!\n</font>\n</p>","metadata":{}},{"cell_type":"code","source":"product_count = Counter(list(article['colour_group_name']))\nprod_count=dict(product_count.most_common(10))\nX=list(prod_count.keys())\ny=prod_count.values()\ncolurs=['#000000','#003366','#ffffff','#ffe6e6','#b3b3b3','#f5f5dc','#00ccff','#e60000','#ccf5ff','#8A865D']\nax=plt.axes()\nax.set_facecolor('#ff6633')\nplt.bar(X,y,color=colurs)\nplt.xticks(X, X, rotation='vertical')\nplt.title(\"TRENDING COLOURS\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-02-11T09:03:22.124013Z","iopub.execute_input":"2022-02-11T09:03:22.124280Z","iopub.status.idle":"2022-02-11T09:03:22.370639Z","shell.execute_reply.started":"2022-02-11T09:03:22.124241Z","shell.execute_reply":"2022-02-11T09:03:22.369882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style='font-family: Trebuchet MS'><font size=5>\n    Shoutout to these MEN & WOMEN in BLACK!!\n</font>\n</p>","metadata":{}},{"cell_type":"markdown","source":"<p style='font-family: Trebuchet MS'><font size=6>\n    Now let's checkout which age group gets 'SHOPOHOLIC OF THE YEAR' award!\n</font>\n</p>","metadata":{}},{"cell_type":"code","source":"customer=pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/customers.csv\")\ncustomer.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-11T09:03:22.372143Z","iopub.execute_input":"2022-02-11T09:03:22.372600Z","iopub.status.idle":"2022-02-11T09:03:27.330374Z","shell.execute_reply.started":"2022-02-11T09:03:22.372561Z","shell.execute_reply":"2022-02-11T09:03:27.329402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"age_count = Counter(list(customer['age']))\nage_count=dict(age_count.most_common(30))\nage_count=pd.DataFrame({'Age': age_count.keys(),\n                      'Count':age_count.values()})\nage_count.head()","metadata":{"execution":{"iopub.status.busy":"2022-02-11T09:03:27.332708Z","iopub.execute_input":"2022-02-11T09:03:27.333011Z","iopub.status.idle":"2022-02-11T09:03:35.473454Z","shell.execute_reply.started":"2022-02-11T09:03:27.332983Z","shell.execute_reply":"2022-02-11T09:03:35.472785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# set figure size\nplt.figure(figsize=(20,12))\n\n# plot polar axis\nax = plt.subplot(111, polar=True)\n\n# remove grid\nplt.axis('off')\n\n# Set the coordinates limits\nupperLimit = 100\nlowerLimit = 30\n\n# Compute max and min in the dataset\nmax = age_count['Count'].max()\n\n# Let's compute heights: they are a conversion of each item value in those new coordinates\n# In our example, 0 in the dataset will be converted to the lowerLimit (10)\n# The maximum will be converted to the upperLimit (100)\nslope = (max - lowerLimit) / max\nheights = slope * age_count.Count + lowerLimit\n\n# Compute the width of each bar. In total we have 2*Pi = 360°\nwidth = 2*np.pi / len(age_count.index)\n\n# Compute the angle each bar is centered on:\nindexes = list(range(1, len(age_count.index)+1))\nangles = [element * width for element in indexes]\nangles\n\n# Draw bars\nbars = ax.bar(\n    x=angles, \n    height=heights, \n    width=width, \n    bottom=lowerLimit,\n    linewidth=2, \n    edgecolor=\"white\",\n    color='#cc2900')\n\nlabelPadding=4\n\nfor bar, angle, height, label in zip(bars,angles, heights, age_count[\"Age\"]):\n\n    # Labels are rotated. Rotation must be specified in degrees :(\n    rotation = np.rad2deg(angle)\n\n    # Flip some labels upside down\n    alignment = \"\"\n    if angle >= np.pi/2 and angle < 3*np.pi/2:\n        alignment = \"right\"\n        rotation = rotation + 180\n    else: \n        alignment = \"left\"\n\n    # Finally add the labels\n    ax.text(\n        x=angle, \n        y=lowerLimit + bar.get_height() + labelPadding, \n        s=label, \n        ha=alignment, \n        va='center', \n        rotation=rotation, \n        rotation_mode=\"anchor\")","metadata":{"execution":{"iopub.status.busy":"2022-02-11T09:04:17.053743Z","iopub.execute_input":"2022-02-11T09:04:17.054045Z","iopub.status.idle":"2022-02-11T09:04:18.765784Z","shell.execute_reply.started":"2022-02-11T09:04:17.054020Z","shell.execute_reply":"2022-02-11T09:04:18.765247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style='font-family: Trebuchet MS'><font size=6>\n    And the 21's WON! &#127942\n</font>\n</p>","metadata":{}},{"cell_type":"markdown","source":"<p style='font-family: Trebuchet MS'><font size=4>\n    ...to be continued!\n</font>\n</p>","metadata":{}}]}