{"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":"#### This notebook contains code to clean and consolidate all data into a single dataset. Please upvote if you find it useful and share your comments if you have any suggestions","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:22:28.886874Z","iopub.execute_input":"2022-04-10T14:22:28.887174Z","iopub.status.idle":"2022-04-10T14:22:28.911923Z","shell.execute_reply.started":"2022-04-10T14:22:28.887097Z","shell.execute_reply":"2022-04-10T14:22:28.911253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_cust=pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/customers.csv\")\ndf_articles=pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/articles.csv\")\ndf_trx=pd.read_csv(\"../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:22:28.913536Z","iopub.execute_input":"2022-04-10T14:22:28.913897Z","iopub.status.idle":"2022-04-10T14:23:32.842820Z","shell.execute_reply.started":"2022-04-10T14:22:28.913860Z","shell.execute_reply":"2022-04-10T14:23:32.841996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Customer Data Cleaning","metadata":{}},{"cell_type":"code","source":"df_cust.info()","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:32.844097Z","iopub.execute_input":"2022-04-10T14:23:32.844354Z","iopub.status.idle":"2022-04-10T14:23:33.393140Z","shell.execute_reply.started":"2022-04-10T14:23:32.844321Z","shell.execute_reply":"2022-04-10T14:23:33.392288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_cust.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:33.394394Z","iopub.execute_input":"2022-04-10T14:23:33.394791Z","iopub.status.idle":"2022-04-10T14:23:33.414467Z","shell.execute_reply.started":"2022-04-10T14:23:33.394755Z","shell.execute_reply":"2022-04-10T14:23:33.412916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### We can see there are some null values in columns: 'FN','Active','club_member_status','fashion_news_frequency'  \n#### And column 'fashion_news_frequency' has 2 'None' values instead of 'NONE'","metadata":{}},{"cell_type":"code","source":"for i in['FN','Active','club_member_status','fashion_news_frequency']:\n    print(\"null values: \",df_cust[i].isna().sum())\n    print(df_cust[i].value_counts())\n    print(\"----------------------------\")","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:33.416294Z","iopub.execute_input":"2022-04-10T14:23:33.416563Z","iopub.status.idle":"2022-04-10T14:23:34.113131Z","shell.execute_reply.started":"2022-04-10T14:23:33.416526Z","shell.execute_reply":"2022-04-10T14:23:34.112393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Replacing NaN values in FN and Active columns with 0\n#### Replacing NaN values in club_member_status column with \"ACTIVE\" and in fashion_news_frequency column with \"NONE\" as they are mode values","metadata":{}},{"cell_type":"code","source":"df_cust['FN'].fillna(value=0,inplace=True)\ndf_cust['Active'].fillna(value=0,inplace=True)\ndf_cust['club_member_status'].fillna(value=\"ACTIVE\",inplace=True)\ndf_cust['fashion_news_frequency'].fillna(value=\"NONE\",inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:34.114251Z","iopub.execute_input":"2022-04-10T14:23:34.115764Z","iopub.status.idle":"2022-04-10T14:23:34.393298Z","shell.execute_reply.started":"2022-04-10T14:23:34.115721Z","shell.execute_reply":"2022-04-10T14:23:34.392586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Replacing 2 \"None\" values with \"NONE\"","metadata":{}},{"cell_type":"code","source":"df_cust['fashion_news_frequency']=df_cust['fashion_news_frequency'].apply(lambda x: \"NONE\" if x==\"None\" else x)","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:34.394391Z","iopub.execute_input":"2022-04-10T14:23:34.394651Z","iopub.status.idle":"2022-04-10T14:23:34.695549Z","shell.execute_reply.started":"2022-04-10T14:23:34.394617Z","shell.execute_reply":"2022-04-10T14:23:34.694812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in['FN','Active','club_member_status','fashion_news_frequency']:\n    print(\"null values: \",df_cust[i].isna().sum())\n    print(df_cust[i].value_counts())\n    print(\"----------------------------\")","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:34.696672Z","iopub.execute_input":"2022-04-10T14:23:34.696906Z","iopub.status.idle":"2022-04-10T14:23:35.421519Z","shell.execute_reply.started":"2022-04-10T14:23:34.696876Z","shell.execute_reply":"2022-04-10T14:23:35.420676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Articles Data Cleaning","metadata":{}},{"cell_type":"code","source":"df_articles.info()","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:35.423382Z","iopub.execute_input":"2022-04-10T14:23:35.423982Z","iopub.status.idle":"2022-04-10T14:23:35.592048Z","shell.execute_reply.started":"2022-04-10T14:23:35.423938Z","shell.execute_reply":"2022-04-10T14:23:35.590244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_articles.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:35.593553Z","iopub.execute_input":"2022-04-10T14:23:35.593849Z","iopub.status.idle":"2022-04-10T14:23:35.622611Z","shell.execute_reply.started":"2022-04-10T14:23:35.593809Z","shell.execute_reply":"2022-04-10T14:23:35.621665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### We see the number of codes do not match the number of respective names for some columns like product name and code","metadata":{}},{"cell_type":"code","source":"df_articles.nunique().sort_values()","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:35.624271Z","iopub.execute_input":"2022-04-10T14:23:35.624570Z","iopub.status.idle":"2022-04-10T14:23:35.790149Z","shell.execute_reply.started":"2022-04-10T14:23:35.624532Z","shell.execute_reply":"2022-04-10T14:23:35.789207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Creating dictionaries for name and code combinations","metadata":{}},{"cell_type":"code","source":"graphical_appearance=pd.Series(df_articles.graphical_appearance_name.values,\n                               index=df_articles.graphical_appearance_no).sort_index().to_dict()\nindex_group=pd.Series(df_articles.index_group_name.values,\n                               index=df_articles.index_group_no).sort_index().to_dict()\nperceived_colour_value=pd.Series(df_articles.perceived_colour_value_name.values,\n                               index=df_articles.perceived_colour_value_id).sort_index().to_dict()\nindex=pd.Series(df_articles.index_name.values,\n                               index=df_articles.index_code).sort_index().to_dict()\nperceived_colour_master=pd.Series(df_articles.perceived_colour_master_name.values,\n                               index=df_articles.perceived_colour_master_id).sort_index().to_dict()\ngarment_group=pd.Series(df_articles.garment_group_name.values,\n                               index=df_articles.garment_group_no).sort_index().to_dict()\ncolour_group=pd.Series(df_articles.colour_group_name.values,\n                               index=df_articles.colour_group_code).sort_index().to_dict()\nsection=pd.Series(df_articles.section_name.values,\n                               index=df_articles.section_no).sort_index().to_dict()\ndepartment=pd.Series(df_articles.department_name.values,\n                               index=df_articles.department_no).sort_index().to_dict()\nproduct_type=pd.Series(df_articles.product_type_name.values,\n                               index=df_articles.product_type_no).sort_index().to_dict()\nproduct=pd.Series(df_articles.prod_name.values,\n                               index=df_articles.product_code).sort_index().to_dict()\ndict_list={'graphical_appearance':graphical_appearance,'index_group':index_group,'perceived_colour_value':perceived_colour_value,\n           'index':index, 'perceived_colour_master':perceived_colour_master,'garment_group':garment_group,\n          'colour_group':colour_group,'section':section,'department':department,'product_type':product_type,\n          \"product\": product}","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:35.791721Z","iopub.execute_input":"2022-04-10T14:23:35.792255Z","iopub.status.idle":"2022-04-10T14:23:37.236238Z","shell.execute_reply.started":"2022-04-10T14:23:35.792211Z","shell.execute_reply":"2022-04-10T14:23:37.235482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dict_list    ","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-04-10T14:23:37.237543Z","iopub.execute_input":"2022-04-10T14:23:37.237808Z","iopub.status.idle":"2022-04-10T14:23:37.295383Z","shell.execute_reply.started":"2022-04-10T14:23:37.237774Z","shell.execute_reply":"2022-04-10T14:23:37.294521Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Finding names having multiple codes each and replacing with single code","metadata":{}},{"cell_type":"code","source":"\ndef find_duplicate_value(col_dict):\n    y=pd.array([str(x) for x in col_dict.values()]).value_counts()\n    y=y[y.values>1]\n    return y.index","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:37.299491Z","iopub.execute_input":"2022-04-10T14:23:37.299857Z","iopub.status.idle":"2022-04-10T14:23:37.305014Z","shell.execute_reply.started":"2022-04-10T14:23:37.299817Z","shell.execute_reply":"2022-04-10T14:23:37.304151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_duplicate_value_keys(col,col_dict):\n    name=find_duplicate_value(col_dict)\n    name_dict={}\n    for i in name:\n        codes=[x for x in col_dict.keys() if col_dict[x]==i]\n#         print( i,\":\",codes)\n        name_dict[i]=codes\n        \n    return name_dict\n\n","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:37.306274Z","iopub.execute_input":"2022-04-10T14:23:37.307237Z","iopub.status.idle":"2022-04-10T14:23:37.315462Z","shell.execute_reply.started":"2022-04-10T14:23:37.307202Z","shell.execute_reply":"2022-04-10T14:23:37.314629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dup_section_dict=get_duplicate_value_keys(df_articles.section_name,section)\nprint(dup_section_dict)\nprint(\"---------------------------------------------------------------------------------------------------------\")\ndup_prodtype_dict=get_duplicate_value_keys(df_articles.product_type_name,product_type)\nprint(dup_prodtype_dict)\nprint(\"---------------------------------------------------------------------------------------------------------\")\ndup_dept_dict=get_duplicate_value_keys(df_articles.department_name,department)\nprint(dup_dept_dict)\nprint(\"---------------------------------------------------------------------------------------------------------\")\ndup_prod_dict=get_duplicate_value_keys(df_articles.prod_name,product)\nprint(dup_prod_dict)","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-04-10T14:23:37.317083Z","iopub.execute_input":"2022-04-10T14:23:37.317362Z","iopub.status.idle":"2022-04-10T14:23:48.887120Z","shell.execute_reply.started":"2022-04-10T14:23:37.317323Z","shell.execute_reply":"2022-04-10T14:23:48.886394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def replace_duplicate_codes(df,name_col,code_col,dup_dict):\n\n    for i in range(df.shape[0]):\n            if(df[name_col][i] in dup_dict.keys()):\n                df[code_col][i]=dup_dict[df[name_col][i]][0]\n    return df","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:48.888112Z","iopub.execute_input":"2022-04-10T14:23:48.888334Z","iopub.status.idle":"2022-04-10T14:23:48.894779Z","shell.execute_reply.started":"2022-04-10T14:23:48.888305Z","shell.execute_reply":"2022-04-10T14:23:48.893666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_articles=replace_duplicate_codes(df_articles,'section_name','section_no',dup_section_dict)\ndf_articles=replace_duplicate_codes(df_articles,'product_type_name','product_type_no',dup_prodtype_dict)\ndf_articles=replace_duplicate_codes(df_articles,'department_name','department_no',dup_dept_dict)\ndf_articles=replace_duplicate_codes(df_articles,'prod_name','product_code',dup_prod_dict)","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:23:48.896162Z","iopub.execute_input":"2022-04-10T14:23:48.896641Z","iopub.status.idle":"2022-04-10T14:24:02.386784Z","shell.execute_reply.started":"2022-04-10T14:23:48.896591Z","shell.execute_reply":"2022-04-10T14:24:02.386059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_articles[df_articles.section_name=='Ladies Other']['section_no'].values","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:24:02.388140Z","iopub.execute_input":"2022-04-10T14:24:02.388384Z","iopub.status.idle":"2022-04-10T14:24:02.409279Z","shell.execute_reply.started":"2022-04-10T14:24:02.388351Z","shell.execute_reply":"2022-04-10T14:24:02.408550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_articles[df_articles.product_type_name=='Umbrella']['product_type_no'].values","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:24:02.410551Z","iopub.execute_input":"2022-04-10T14:24:02.410984Z","iopub.status.idle":"2022-04-10T14:24:02.433006Z","shell.execute_reply.started":"2022-04-10T14:24:02.410940Z","shell.execute_reply":"2022-04-10T14:24:02.432276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_articles[df_articles.department_name=='Knitwear']['department_no'].values","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:24:02.434141Z","iopub.execute_input":"2022-04-10T14:24:02.435074Z","iopub.status.idle":"2022-04-10T14:24:02.458972Z","shell.execute_reply.started":"2022-04-10T14:24:02.435038Z","shell.execute_reply":"2022-04-10T14:24:02.458247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_articles[df_articles.prod_name=='Molly dress']['product_code'].values","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:24:02.460286Z","iopub.execute_input":"2022-04-10T14:24:02.460783Z","iopub.status.idle":"2022-04-10T14:24:02.481534Z","shell.execute_reply.started":"2022-04-10T14:24:02.460747Z","shell.execute_reply":"2022-04-10T14:24:02.480623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### The number of names and codes match for section, product type and department, but there is difference in product name and code. This means that there are some codes which are assigned to more than one name","metadata":{}},{"cell_type":"code","source":"df_articles.nunique().sort_values()","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:24:02.483191Z","iopub.execute_input":"2022-04-10T14:24:02.483528Z","iopub.status.idle":"2022-04-10T14:24:02.633932Z","shell.execute_reply.started":"2022-04-10T14:24:02.483492Z","shell.execute_reply":"2022-04-10T14:24:02.633269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Finding missing product names from the dictionary","metadata":{}},{"cell_type":"code","source":"missing_prod_name=[]\nfor i in df_articles.prod_name.unique():\n    if i not in product.values():\n        missing_prod_name.append(i)\n        \nmissing_prod_name","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-04-10T14:24:02.635239Z","iopub.execute_input":"2022-04-10T14:24:02.635508Z","iopub.status.idle":"2022-04-10T14:24:23.840142Z","shell.execute_reply.started":"2022-04-10T14:24:02.635475Z","shell.execute_reply":"2022-04-10T14:24:23.839479Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Finding product codes associated with missing product names and adding those names to the dictionary","metadata":{}},{"cell_type":"code","source":"\nfor i in missing_prod_name:\n    x= df_articles.loc[df_articles.prod_name==i,'product_code']\n    code=x.values[0]\n    y=df_articles[df_articles.product_code==code][['product_code','prod_name']]\n    product[code]=set(y.prod_name)\n    missing_prod_name=[x for x in missing_prod_name if x not in product[code]]\n    ","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:24:23.841561Z","iopub.execute_input":"2022-04-10T14:24:23.842071Z","iopub.status.idle":"2022-04-10T14:25:00.172390Z","shell.execute_reply.started":"2022-04-10T14:24:23.842032Z","shell.execute_reply":"2022-04-10T14:25:00.171653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_prod_name","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:25:00.173807Z","iopub.execute_input":"2022-04-10T14:25:00.174045Z","iopub.status.idle":"2022-04-10T14:25:00.179484Z","shell.execute_reply.started":"2022-04-10T14:25:00.174012Z","shell.execute_reply":"2022-04-10T14:25:00.178811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### The missing product names are now added to dictionary keys as set","metadata":{}},{"cell_type":"code","source":"product","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-04-10T14:25:00.180975Z","iopub.execute_input":"2022-04-10T14:25:00.181524Z","iopub.status.idle":"2022-04-10T14:25:00.228180Z","shell.execute_reply.started":"2022-04-10T14:25:00.181485Z","shell.execute_reply":"2022-04-10T14:25:00.227502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Some of the columns have -1 values probably referring to missing data","metadata":{}},{"cell_type":"code","source":"print(\"columns having -1 values: \\n\")\ncols_missing_value=[]\nfor i in df_articles.columns:\n    if (-1 in df_articles[i].value_counts()):\n        cols_missing_value.append(i)\nprint(cols_missing_value)        ","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:25:00.229561Z","iopub.execute_input":"2022-04-10T14:25:00.230009Z","iopub.status.idle":"2022-04-10T14:25:00.500350Z","shell.execute_reply.started":"2022-04-10T14:25:00.229972Z","shell.execute_reply":"2022-04-10T14:25:00.499636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### -1 value in all code columns refer to the 'Unknown' category. Therefore keeping -1 values as it is","metadata":{}},{"cell_type":"code","source":"product_type[-1]","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:25:00.501463Z","iopub.execute_input":"2022-04-10T14:25:00.501908Z","iopub.status.idle":"2022-04-10T14:25:00.510210Z","shell.execute_reply.started":"2022-04-10T14:25:00.501867Z","shell.execute_reply":"2022-04-10T14:25:00.508852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"graphical_appearance[-1]","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:25:00.511383Z","iopub.execute_input":"2022-04-10T14:25:00.511697Z","iopub.status.idle":"2022-04-10T14:25:00.519491Z","shell.execute_reply.started":"2022-04-10T14:25:00.511669Z","shell.execute_reply":"2022-04-10T14:25:00.518488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"colour_group[-1]","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:25:00.521014Z","iopub.execute_input":"2022-04-10T14:25:00.521493Z","iopub.status.idle":"2022-04-10T14:25:00.527904Z","shell.execute_reply.started":"2022-04-10T14:25:00.521459Z","shell.execute_reply":"2022-04-10T14:25:00.527176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"perceived_colour_value[-1]","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:25:00.529342Z","iopub.execute_input":"2022-04-10T14:25:00.529831Z","iopub.status.idle":"2022-04-10T14:25:00.537292Z","shell.execute_reply.started":"2022-04-10T14:25:00.529795Z","shell.execute_reply":"2022-04-10T14:25:00.536454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"perceived_colour_master[-1]","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:25:00.538744Z","iopub.execute_input":"2022-04-10T14:25:00.539013Z","iopub.status.idle":"2022-04-10T14:25:00.546904Z","shell.execute_reply.started":"2022-04-10T14:25:00.538962Z","shell.execute_reply":"2022-04-10T14:25:00.545894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_cust.to_csv(\"customers_clean.csv\",index=False)\ndf_articles.to_csv(\"articles_clean.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:25:00.549250Z","iopub.execute_input":"2022-04-10T14:25:00.549663Z","iopub.status.idle":"2022-04-10T14:25:13.854209Z","shell.execute_reply.started":"2022-04-10T14:25:00.549623Z","shell.execute_reply":"2022-04-10T14:25:13.853327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Merging Transaction data with Customer and Articles data to form final dataset","metadata":{}},{"cell_type":"code","source":"df_trx.info()","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:25:13.857278Z","iopub.execute_input":"2022-04-10T14:25:13.857568Z","iopub.status.idle":"2022-04-10T14:25:13.869330Z","shell.execute_reply.started":"2022-04-10T14:25:13.857528Z","shell.execute_reply":"2022-04-10T14:25:13.868493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_trx.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:25:13.870704Z","iopub.execute_input":"2022-04-10T14:25:13.871039Z","iopub.status.idle":"2022-04-10T14:25:13.884483Z","shell.execute_reply.started":"2022-04-10T14:25:13.870986Z","shell.execute_reply":"2022-04-10T14:25:13.883546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.merge(left=df_cust,right=df_trx,on=\"customer_id\",how=\"left\")\ndf=pd.merge(left=df,right=df_articles,on='article_id',how='left')","metadata":{"execution":{"iopub.status.busy":"2022-04-10T14:25:13.885900Z","iopub.execute_input":"2022-04-10T14:25:13.886330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Final dataset: df","metadata":{}},{"cell_type":"code","source":"df.info()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.nunique()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv(\"hm_data.csv\",index=False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}