{"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":"## Basic EDA follwed by some ploty express visualizations","metadata":{}},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport gc\nimport os\nimport plotly.express as plt\nfrom plotly.subplots import make_subplots\nimport plotly.graph_objects as go\ngc.collect()","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-04-12T07:15:45.521620Z","iopub.execute_input":"2022-04-12T07:15:45.522629Z","iopub.status.idle":"2022-04-12T07:15:47.822812Z","shell.execute_reply.started":"2022-04-12T07:15:45.522480Z","shell.execute_reply":"2022-04-12T07:15:47.821721Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")\narticles = 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\")\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T06:56:05.180938Z","iopub.execute_input":"2022-04-12T06:56:05.181207Z","iopub.status.idle":"2022-04-12T06:57:27.466148Z","shell.execute_reply.started":"2022-04-12T06:56:05.181172Z","shell.execute_reply":"2022-04-12T06:57:27.465067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Total Transactions \",trans.shape[0] ,\"Total Articles \", articles.shape[0] ,\"Total Customers \", customers.shape[0])","metadata":{"execution":{"iopub.status.busy":"2022-04-12T06:57:27.467824Z","iopub.execute_input":"2022-04-12T06:57:27.468130Z","iopub.status.idle":"2022-04-12T06:57:27.476073Z","shell.execute_reply.started":"2022-04-12T06:57:27.468098Z","shell.execute_reply":"2022-04-12T06:57:27.475154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def missing_value(data):\n    mis_data = data.isnull().sum().sort_values(ascending=False)\n    per_data = ((data.isnull().sum()/data.isnull().count())*100).sort_values(ascending=False)\n    #nunique_data = mis_data.nunique_data()\n    ret_data = pd.concat([per_data,mis_data],axis=1,keys=[\"Percentage Missing\",\"Missing Count\"])\n    return ret_data[ret_data[\"Missing Count\"]>0] if ret_data[ret_data[\"Missing Count\"]>0].shape[0]>0 else \"No missing Value\"\n\ndef unique_data(data):\n    tot = data.count()\n    nunique = data.nunique().sort_values()\n    #perc = (data.nunique()/data.count()*100).sort_values(ascending=False)\n    ret_data =  pd.concat([tot,nunique],keys=[\"Total\",\"Unique Values\"],axis=1)\n    return ret_data.sort_values(by=\"Unique Values\")","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:09:04.664932Z","iopub.execute_input":"2022-04-12T07:09:04.665380Z","iopub.status.idle":"2022-04-12T07:09:04.675663Z","shell.execute_reply.started":"2022-04-12T07:09:04.665342Z","shell.execute_reply":"2022-04-12T07:09:04.674867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_value(articles)","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:01:04.591050Z","iopub.execute_input":"2022-04-12T07:01:04.591982Z","iopub.status.idle":"2022-04-12T07:01:05.099712Z","shell.execute_reply.started":"2022-04-12T07:01:04.591925Z","shell.execute_reply":"2022-04-12T07:01:05.098616Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unique_data(articles)","metadata":{"execution":{"iopub.status.busy":"2022-04-12T06:57:52.406090Z","iopub.execute_input":"2022-04-12T06:57:52.406484Z","iopub.status.idle":"2022-04-12T06:57:52.774072Z","shell.execute_reply.started":"2022-04-12T06:57:52.406442Z","shell.execute_reply":"2022-04-12T06:57:52.773132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()\nmissing_value(customers)","metadata":{"execution":{"iopub.status.busy":"2022-04-12T06:59:22.348101Z","iopub.execute_input":"2022-04-12T06:59:22.348463Z","iopub.status.idle":"2022-04-12T06:59:24.531158Z","shell.execute_reply.started":"2022-04-12T06:59:22.348431Z","shell.execute_reply":"2022-04-12T06:59:24.530090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()\nunique_data(customers)","metadata":{"execution":{"iopub.status.busy":"2022-04-12T06:59:39.361282Z","iopub.execute_input":"2022-04-12T06:59:39.362058Z","iopub.status.idle":"2022-04-12T06:59:42.234838Z","shell.execute_reply.started":"2022-04-12T06:59:39.362014Z","shell.execute_reply":"2022-04-12T06:59:42.233401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()\nmissing_value(trans)","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:09:16.405561Z","iopub.execute_input":"2022-04-12T07:09:16.406651Z","iopub.status.idle":"2022-04-12T07:09:38.203976Z","shell.execute_reply.started":"2022-04-12T07:09:16.406580Z","shell.execute_reply":"2022-04-12T07:09:38.202792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()\nunique_data(trans)","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:10:02.544652Z","iopub.execute_input":"2022-04-12T07:10:02.545068Z","iopub.status.idle":"2022-04-12T07:10:24.760677Z","shell.execute_reply.started":"2022-04-12T07:10:02.545023Z","shell.execute_reply":"2022-04-12T07:10:24.759758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()\ntrans_artcile = pd.merge(trans,articles,on=\"article_id\")\ndel trans\ndel articles\ndel customers\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:10:24.762465Z","iopub.execute_input":"2022-04-12T07:10:24.762734Z","iopub.status.idle":"2022-04-12T07:12:23.850596Z","shell.execute_reply.started":"2022-04-12T07:10:24.762701Z","shell.execute_reply":"2022-04-12T07:12:23.849424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Ploting","metadata":{}},{"cell_type":"code","source":"product_type_name_count = trans_artcile[\"product_type_name\"].value_counts().reset_index()\nproduct_type_name_count.columns = [\"Product Type Name\",\"Count\"]\nfig = plt.bar(product_type_name_count , x = \"Product Type Name\",y = \"Count\" ,\n              barmode=\"group\",title=\"Different types of Product per transactions\")\nfig.show()\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:12:23.852759Z","iopub.execute_input":"2022-04-12T07:12:23.853216Z","iopub.status.idle":"2022-04-12T07:12:29.993240Z","shell.execute_reply.started":"2022-04-12T07:12:23.853172Z","shell.execute_reply":"2022-04-12T07:12:29.992212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#trans_artcile[\"index_group_name\"].value_counts().plot(kind=\"bar\")\nindex_group_name_count = trans_artcile[\"index_group_name\"].value_counts().reset_index()\nindex_group_name_count.columns = [\"Group Name\",\"Count\"]\nfig = plt.bar(index_group_name_count , x = \"Group Name\",y = \"Count\" ,\n              barmode=\"group\",title=\"Different type of Group per transactions\")\nfig.show()\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:12:29.994675Z","iopub.execute_input":"2022-04-12T07:12:29.994963Z","iopub.status.idle":"2022-04-12T07:12:34.862813Z","shell.execute_reply.started":"2022-04-12T07:12:29.994927Z","shell.execute_reply":"2022-04-12T07:12:34.861730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ngarment_group_name_count = trans_artcile[\"garment_group_name\"].value_counts().reset_index()\ngarment_group_name_count.columns = [\"Garment Group Name\",\"Count\"]\nfig = plt.bar(garment_group_name_count , x = \"Garment Group Name\",y = \"Count\" , \n              barmode=\"group\" , title =\"Different type of garment group per Transactions\")\nfig.show()\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:12:34.865768Z","iopub.execute_input":"2022-04-12T07:12:34.866262Z","iopub.status.idle":"2022-04-12T07:12:39.691161Z","shell.execute_reply.started":"2022-04-12T07:12:34.866183Z","shell.execute_reply":"2022-04-12T07:12:39.690018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"section_count = trans_artcile.section_name.value_counts().reset_index()\nsection_count.columns = [\"Section Name\",\"Count\"]\nfig = plt.bar(section_count , x = \"Section Name\",y = \"Count\" , barmode=\"group\")\nfig.show()\n#print(section_count)\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:12:39.692704Z","iopub.execute_input":"2022-04-12T07:12:39.692980Z","iopub.status.idle":"2022-04-12T07:12:44.558544Z","shell.execute_reply.started":"2022-04-12T07:12:39.692947Z","shell.execute_reply":"2022-04-12T07:12:44.557315Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_artcile[\"t_dat\"] =  pd.to_datetime(trans_artcile[\"t_dat\"])\ngc.collect()\ntrans_artcile[\"weekday\"] = trans_artcile[\"t_dat\"].dt.weekday\ngc.collect()\ntrans_artcile[\"month\"] = trans_artcile[\"t_dat\"].dt.month\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:12:44.560552Z","iopub.execute_input":"2022-04-12T07:12:44.560843Z","iopub.status.idle":"2022-04-12T07:13:00.292057Z","shell.execute_reply.started":"2022-04-12T07:12:44.560810Z","shell.execute_reply":"2022-04-12T07:13:00.291032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"section_name_month = trans_artcile.groupby([\"month\"])[\"section_name\"]\ngc.collect()\nsection_name_day = trans_artcile.groupby([\"weekday\"])[\"section_name\"]\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:13:00.293577Z","iopub.execute_input":"2022-04-12T07:13:00.293935Z","iopub.status.idle":"2022-04-12T07:13:00.768771Z","shell.execute_reply.started":"2022-04-12T07:13:00.293898Z","shell.execute_reply":"2022-04-12T07:13:00.767695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()\nname=[\"Jan\",\"Feb\",\"March\",\"April\",\"May\",\"June\",\"July\",\"Aug\",\"Sept\",\"Oct\",\"Nov\",\"Dec\"]\nfig = make_subplots(3,4,subplot_titles=name,)\n\nfor i in range(12):\n    month_section_name = section_name_month.get_group(i+1).reset_index()\n    month_section_name =  month_section_name.section_name.value_counts().reset_index().head(10)\n    month_section_name.columns = [\"section_name\",\"count\"]\n    fig.add_trace(go.Bar(name=name[i],x=month_section_name[\"section_name\"],\n                          y=month_section_name[\"count\"],showlegend=False),\n                  row=i//4+1,col=i%4+1)\nfig.update_layout(height=1600, width=1000,title=\"Monthwise Sale of Different Sections over all the Transactions\")\ngc.collect()\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:13:00.770513Z","iopub.execute_input":"2022-04-12T07:13:00.770837Z","iopub.status.idle":"2022-04-12T07:13:09.297989Z","shell.execute_reply.started":"2022-04-12T07:13:00.770796Z","shell.execute_reply":"2022-04-12T07:13:09.296947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()\nname=[\"Monday\",\"Tuesday\",\"Wednesday\",\"Thrusday\",\"Friday\",\"Saturday\",\"Sunday\"]\nfig = make_subplots(2,4,subplot_titles=name,)\n\nfor i in range(7):\n    day_section_name = section_name_day.get_group(i).reset_index()\n    day_section_name =  day_section_name.section_name.value_counts().reset_index().head(10)\n    day_section_name.columns = [\"section_name\",\"count\"]\n    fig.add_trace(go.Bar(name=name[i],x=day_section_name[\"section_name\"],\n                          y=day_section_name[\"count\"],showlegend=False),\n                  row=i//4+1,col=i%4+1)\nfig.update_layout(height=1200, width=1000,title=\"Daywise Sale of Different Sections over all the Transactions\")\ngc.collect()\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:13:09.300369Z","iopub.execute_input":"2022-04-12T07:13:09.301180Z","iopub.status.idle":"2022-04-12T07:13:18.218560Z","shell.execute_reply.started":"2022-04-12T07:13:09.301127Z","shell.execute_reply":"2022-04-12T07:13:18.217484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del trans_artcile\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:13:18.222250Z","iopub.execute_input":"2022-04-12T07:13:18.222575Z","iopub.status.idle":"2022-04-12T07:13:18.465100Z","shell.execute_reply.started":"2022-04-12T07:13:18.222537Z","shell.execute_reply":"2022-04-12T07:13:18.463847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")\ngc.collect()\ncustomers = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/customers.csv\")\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:15:59.713494Z","iopub.execute_input":"2022-04-12T07:15:59.713886Z","iopub.status.idle":"2022-04-12T07:17:20.272338Z","shell.execute_reply.started":"2022-04-12T07:15:59.713838Z","shell.execute_reply":"2022-04-12T07:17:20.271173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans_cust = pd.merge(trans,customers,on=\"customer_id\")\ngc.collect()\ndel trans\ndel customers\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:17:20.274779Z","iopub.execute_input":"2022-04-12T07:17:20.275261Z","iopub.status.idle":"2022-04-12T07:17:54.380609Z","shell.execute_reply.started":"2022-04-12T07:17:20.275203Z","shell.execute_reply":"2022-04-12T07:17:54.379662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()\ntrans_cust.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:17:54.382149Z","iopub.execute_input":"2022-04-12T07:17:54.382447Z","iopub.status.idle":"2022-04-12T07:17:54.581317Z","shell.execute_reply.started":"2022-04-12T07:17:54.382408Z","shell.execute_reply":"2022-04-12T07:17:54.580165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()\ntrans_cust_age = trans_cust.age.value_counts().reset_index()\ntrans_cust_age.columns = [\"Age\",\"Count\"]\nfig = plt.bar(trans_cust_age,x=\"Age\",y=\"Count\",\n              title=\"Agewise distribution in all Transcations\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:17:54.583539Z","iopub.execute_input":"2022-04-12T07:17:54.583828Z","iopub.status.idle":"2022-04-12T07:17:56.409219Z","shell.execute_reply.started":"2022-04-12T07:17:54.583797Z","shell.execute_reply":"2022-04-12T07:17:56.408063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()\ncust_club_member_status = trans_cust.club_member_status.value_counts().reset_index()\ncust_club_member_status.columns = [\"Club Member Status\",\"Count\"]\nfig = plt.bar(cust_club_member_status,x=\"Club Member Status\",y=\"Count\",\n              title=\"Club members distribution in all transcations\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:17:56.411006Z","iopub.execute_input":"2022-04-12T07:17:56.411725Z","iopub.status.idle":"2022-04-12T07:18:01.552463Z","shell.execute_reply.started":"2022-04-12T07:17:56.411672Z","shell.execute_reply":"2022-04-12T07:18:01.551331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del trans_cust\ndel trans_cust_age\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:18:01.554358Z","iopub.execute_input":"2022-04-12T07:18:01.554744Z","iopub.status.idle":"2022-04-12T07:18:01.753348Z","shell.execute_reply.started":"2022-04-12T07:18:01.554691Z","shell.execute_reply":"2022-04-12T07:18:01.752079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trans = pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\",parse_dates=[\"t_dat\"],\n                    index_col=\"t_dat\")\ntrans.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:20:00.858578Z","iopub.execute_input":"2022-04-12T07:20:00.859015Z","iopub.status.idle":"2022-04-12T07:20:50.527592Z","shell.execute_reply.started":"2022-04-12T07:20:00.858967Z","shell.execute_reply":"2022-04-12T07:20:50.526914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()\n\nplt.line(trans.resample(\"D\").sum(),y=\"price\",title=\"Total Transaction Amount Daywise\")","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:38:10.133730Z","iopub.execute_input":"2022-04-12T07:38:10.134765Z","iopub.status.idle":"2022-04-12T07:38:11.566919Z","shell.execute_reply.started":"2022-04-12T07:38:10.134690Z","shell.execute_reply":"2022-04-12T07:38:11.565927Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()\n\nplt.bar(trans.resample(\"M\").sum(),y=\"price\",title=\"Total Transaction Amount Monthly\")","metadata":{"execution":{"iopub.status.busy":"2022-04-12T07:44:46.219730Z","iopub.execute_input":"2022-04-12T07:44:46.220232Z","iopub.status.idle":"2022-04-12T07:44:47.518213Z","shell.execute_reply.started":"2022-04-12T07:44:46.220180Z","shell.execute_reply":"2022-04-12T07:44:47.517042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Please upvote if you find it some usefull :)  to be continued in next verions..","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}