{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":31254,"databundleVersionId":3103714,"sourceType":"competition"}],"dockerImageVersionId":30746,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-08-19T15:46:28.390542Z","iopub.execute_input":"2024-08-19T15:46:28.390845Z","iopub.status.idle":"2024-08-19T15:46:29.325086Z","shell.execute_reply.started":"2024-08-19T15:46:28.390818Z","shell.execute_reply":"2024-08-19T15:46:29.324154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_df = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv')\ncustomers_df = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv')\ntransactions_df = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:46:29.326649Z","iopub.execute_input":"2024-08-19T15:46:29.327047Z","iopub.status.idle":"2024-08-19T15:47:42.586145Z","shell.execute_reply.started":"2024-08-19T15:46:29.327021Z","shell.execute_reply":"2024-08-19T15:47:42.585274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_df.t_dat = pd.to_datetime(transactions_df.t_dat)","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:42.587336Z","iopub.execute_input":"2024-08-19T15:47:42.587639Z","iopub.status.idle":"2024-08-19T15:47:47.847427Z","shell.execute_reply.started":"2024-08-19T15:47:42.587612Z","shell.execute_reply":"2024-08-19T15:47:47.846559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SalesPerMonth = transactions_df.copy()\nSalesPerMonth","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:47.850133Z","iopub.execute_input":"2024-08-19T15:47:47.850575Z","iopub.status.idle":"2024-08-19T15:47:48.584721Z","shell.execute_reply.started":"2024-08-19T15:47:47.850541Z","shell.execute_reply":"2024-08-19T15:47:48.583837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SalesPerMonth['t_dat'] = SalesPerMonth['t_dat'].dt.to_period('M')\n\nSalesPerMonth['t_dat'] = SalesPerMonth['t_dat'].dt.to_timestamp()","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:48.585995Z","iopub.execute_input":"2024-08-19T15:47:48.586381Z","iopub.status.idle":"2024-08-19T15:47:53.100325Z","shell.execute_reply.started":"2024-08-19T15:47:48.586345Z","shell.execute_reply":"2024-08-19T15:47:53.099417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nSalesPerMonthGroup = SalesPerMonth.groupby('t_dat')['price'].sum().reset_index()","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:53.101332Z","iopub.execute_input":"2024-08-19T15:47:53.101609Z","iopub.status.idle":"2024-08-19T15:47:53.798782Z","shell.execute_reply.started":"2024-08-19T15:47:53.101585Z","shell.execute_reply":"2024-08-19T15:47:53.797754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize= (36,10))\nplt.title(\"SalesPerMonth\")\nplt.xlabel(\"Time\")\nplt.ylabel(\"Sales Price\")\nplt.plot(SalesPerMonthGroup['t_dat'], SalesPerMonthGroup['price'], color = 'blue',marker= 'o', linestyle= '-')\nplt.grid(True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:53.800016Z","iopub.execute_input":"2024-08-19T15:47:53.800318Z","iopub.status.idle":"2024-08-19T15:47:54.348974Z","shell.execute_reply.started":"2024-08-19T15:47:53.800293Z","shell.execute_reply":"2024-08-19T15:47:54.348131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dailySales = transactions_df.groupby('t_dat')['price'].sum().reset_index()","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:54.350274Z","iopub.execute_input":"2024-08-19T15:47:54.350895Z","iopub.status.idle":"2024-08-19T15:47:55.015544Z","shell.execute_reply.started":"2024-08-19T15:47:54.350861Z","shell.execute_reply":"2024-08-19T15:47:55.014756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(36,10))\nplt.title(\"Sales Daily\")\nplt.plot(dailySales['t_dat'], dailySales['price'], color = 'red', marker= 'o', linestyle= '-')\nplt.xlabel(\"Time\")\nplt.ylabel(\"Sale Price\")\nplt.grid(True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:55.016852Z","iopub.execute_input":"2024-08-19T15:47:55.017253Z","iopub.status.idle":"2024-08-19T15:47:55.564205Z","shell.execute_reply.started":"2024-08-19T15:47:55.017218Z","shell.execute_reply":"2024-08-19T15:47:55.563284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dailySales.loc[dailySales.price == dailySales.price.max(), 't_dat']","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:55.567496Z","iopub.execute_input":"2024-08-19T15:47:55.567824Z","iopub.status.idle":"2024-08-19T15:47:55.575908Z","shell.execute_reply.started":"2024-08-19T15:47:55.567798Z","shell.execute_reply":"2024-08-19T15:47:55.574871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mostSalesDaily = transactions_df.loc[transactions_df.t_dat == \"2019-09-28\"]\nmostSalesDaily","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:55.577286Z","iopub.execute_input":"2024-08-19T15:47:55.577596Z","iopub.status.idle":"2024-08-19T15:47:55.687219Z","shell.execute_reply.started":"2024-08-19T15:47:55.577570Z","shell.execute_reply":"2024-08-19T15:47:55.686217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(mostSalesDaily.customer_id.unique()).size","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:55.688336Z","iopub.execute_input":"2024-08-19T15:47:55.688633Z","iopub.status.idle":"2024-08-19T15:47:55.724462Z","shell.execute_reply.started":"2024-08-19T15:47:55.688607Z","shell.execute_reply":"2024-08-19T15:47:55.723532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mostSalesDaily.article_id.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:55.725493Z","iopub.execute_input":"2024-08-19T15:47:55.725799Z","iopub.status.idle":"2024-08-19T15:47:55.740908Z","shell.execute_reply.started":"2024-08-19T15:47:55.725775Z","shell.execute_reply":"2024-08-19T15:47:55.740160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"top10 = mostSalesDaily.article_id.value_counts().head(10).index\ntop10","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:55.742070Z","iopub.execute_input":"2024-08-19T15:47:55.742437Z","iopub.status.idle":"2024-08-19T15:47:55.753141Z","shell.execute_reply.started":"2024-08-19T15:47:55.742403Z","shell.execute_reply":"2024-08-19T15:47:55.752162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"articles_df.loc[articles_df.article_id.isin(top10)]","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:55.754272Z","iopub.execute_input":"2024-08-19T15:47:55.754532Z","iopub.status.idle":"2024-08-19T15:47:55.781634Z","shell.execute_reply.started":"2024-08-19T15:47:55.754510Z","shell.execute_reply":"2024-08-19T15:47:55.780769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dailySalesItem = transactions_df.groupby('t_dat').size()","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:55.782665Z","iopub.execute_input":"2024-08-19T15:47:55.782938Z","iopub.status.idle":"2024-08-19T15:47:56.388197Z","shell.execute_reply.started":"2024-08-19T15:47:55.782915Z","shell.execute_reply":"2024-08-19T15:47:56.387238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dailySalesItem = dailySalesItem.reset_index(name='items')","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:47:56.389292Z","iopub.execute_input":"2024-08-19T15:47:56.389557Z","iopub.status.idle":"2024-08-19T15:47:56.395013Z","shell.execute_reply.started":"2024-08-19T15:47:56.389534Z","shell.execute_reply":"2024-08-19T15:47:56.394144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dailySalesItem","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:55:45.275769Z","iopub.execute_input":"2024-08-19T15:55:45.276167Z","iopub.status.idle":"2024-08-19T15:55:45.287630Z","shell.execute_reply.started":"2024-08-19T15:55:45.276137Z","shell.execute_reply":"2024-08-19T15:55:45.286693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(36, 10))\nplt.title(\"Sales Daily\")\nplt.plot(dailySalesItem['t_dat'], dailySalesItem['items'], color='red', marker='o', linestyle='-')\nplt.xlabel(\"Time\")\nplt.ylabel(\"Sale items\")\nplt.grid(True)\nplt.show()\nplt.figure(figsize=(36,10))\nplt.title(\"Sales Daily\")\nplt.plot(dailySales['t_dat'], dailySales['price'], color = 'blue', marker= 'o', linestyle= '-')\nplt.xlabel(\"Time\")\nplt.ylabel(\"Sale Price\")\nplt.grid(True)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:56:31.017839Z","iopub.execute_input":"2024-08-19T15:56:31.018356Z","iopub.status.idle":"2024-08-19T15:56:32.091566Z","shell.execute_reply.started":"2024-08-19T15:56:31.018315Z","shell.execute_reply":"2024-08-19T15:56:32.090635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:56:36.323448Z","iopub.execute_input":"2024-08-19T15:56:36.323821Z","iopub.status.idle":"2024-08-19T15:56:36.981193Z","shell.execute_reply.started":"2024-08-19T15:56:36.323791Z","shell.execute_reply":"2024-08-19T15:56:36.980325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"salesdailyreg = dailySales.merge(dailySalesItem[['t_dat','items']], on='t_dat', how='left')","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:56:40.581469Z","iopub.execute_input":"2024-08-19T15:56:40.581844Z","iopub.status.idle":"2024-08-19T15:56:40.590350Z","shell.execute_reply.started":"2024-08-19T15:56:40.581811Z","shell.execute_reply":"2024-08-19T15:56:40.589301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"salesdailyreg","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:56:41.978023Z","iopub.execute_input":"2024-08-19T15:56:41.978391Z","iopub.status.idle":"2024-08-19T15:56:41.990405Z","shell.execute_reply.started":"2024-08-19T15:56:41.978354Z","shell.execute_reply":"2024-08-19T15:56:41.989427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:56:44.477428Z","iopub.execute_input":"2024-08-19T15:56:44.478358Z","iopub.status.idle":"2024-08-19T15:56:46.441726Z","shell.execute_reply.started":"2024-08-19T15:56:44.478325Z","shell.execute_reply":"2024-08-19T15:56:46.440196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"salesdailyreg","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:57:10.378787Z","iopub.execute_input":"2024-08-19T15:57:10.379178Z","iopub.status.idle":"2024-08-19T15:57:10.391526Z","shell.execute_reply.started":"2024-08-19T15:57:10.379149Z","shell.execute_reply":"2024-08-19T15:57:10.390494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set(style=\"whitegrid\")\n\n# Scatter plot with regression line\nplt.figure(figsize=(16, 8))\nsns.regplot(x='price', y='items', data=salesdailyreg)\n\nplt.title('Sales Revenue vs. Items Sold')\nplt.xlabel('Number of Items Sold')\nplt.ylabel('Sales Revenue')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-08-19T15:57:14.038087Z","iopub.execute_input":"2024-08-19T15:57:14.038451Z","iopub.status.idle":"2024-08-19T15:57:14.588839Z","shell.execute_reply.started":"2024-08-19T15:57:14.038424Z","shell.execute_reply":"2024-08-19T15:57:14.587934Z"},"trusted":true},"execution_count":null,"outputs":[]}]}