{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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 in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport seaborn as sns  # visualization tool\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"data1 = pd.read_csv('../input/merchants.csv')\ndata2 = pd.read_csv('../input/new_merchant_transactions.csv')\ndata3 = pd.read_csv('../input/test.csv')\ndata4 = pd.read_csv('../input/train.csv')\ndata5 = pd.read_csv('../input/sample_submission.csv')\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"060e7ce580cbc515e432c353c980ef89470aa13e"},"cell_type":"code","source":"data1.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c56ddbdd7bb0e824e3080e05c94372e4d9efd9a4"},"cell_type":"code","source":"data2.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fd958ef6168ad30eb181e2e56efd6403af52120e"},"cell_type":"code","source":"# correlation map\nf,ax = plt.subplots(figsize = (18,18))\nsns.heatmap(data1.corr(), annot=True, linewidths=.5, fmt= '.1f',ax=ax,center = 0,vmax = 1,vmin = -0.2)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"06431b498c3ccdf29c130147e01a26bbbafcc12b"},"cell_type":"code","source":"# correlation map\nf,ax = plt.subplots(figsize = (18,18))\nsns.heatmap(data2.corr(), annot=True, linewidths=.5, fmt= '.1f',ax=ax,center = 0,vmax = 1,vmin = -0.2)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7a8109f6ae13dd3ea34fab7bd02cb5a7b3334888"},"cell_type":"code","source":"data1.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"076634cbc5f5fb832417e0bec097b2ac7ab611b1"},"cell_type":"code","source":"data1.tail()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"38c26221d2baf822a5e930f9a4a94165bf9f1ff8"},"cell_type":"code","source":"data2.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"24585aad6bd4749ccaff47f37089a765b4e55e95"},"cell_type":"code","source":"data2.tail()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"117bb4cff2a66b08a45349e219b157077a82f846"},"cell_type":"code","source":"data1.plot(kind='scatter', x='avg_sales_lag3', y='avg_sales_lag6',alpha = 0.9,color = 'green',figsize=(16,16))\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"133ce26902eb6760d4b0481c18c6b3935ef8e9c5"},"cell_type":"code","source":"data1.plot(kind='scatter', x='avg_sales_lag3', y='avg_sales_lag12',alpha = 0.9,color = 'red',figsize=(16,16))\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4671d0eb7a1f3746928ff87d6fbdd6f1d89010b7"},"cell_type":"code","source":"data1.plot(kind='scatter', x='avg_sales_lag6', y='avg_sales_lag12',alpha = 0.9,color = 'blue',figsize=(16,16))\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fc53c8496c4711c7c8695165bb730e356664abb5"},"cell_type":"code","source":"data2.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"297b45bb32215fb29c6c7733d359712bcc65bd73"},"cell_type":"code","source":"data2.plot(kind='scatter', x='purchase_amount', y='installments',alpha = 0.9,color = 'orange',figsize=(16,16))\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d74ba46e85d2f082956f9cb2f22b23e1a509fc39"},"cell_type":"code","source":"#data2.plot(kind='scatter', x='card_id', y='city_id',alpha = 0.9,color = 'orange',figsize=(16,16))\n#plt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"83d51fde7cfb91c4255b4da31663a1ef767ad14f"},"cell_type":"code","source":"data1.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"24116d707e2d118ae56d7cd83752c870fb74a6e2"},"cell_type":"code","source":"print(data1['merchant_id'].value_counts(dropna =False))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"39f3871180d91ca90f10ea2b5b1a9186afa4a154"},"cell_type":"code","source":"print(data1['category_4'].value_counts(dropna =False))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ac05c1220909ff607e55697d0f091fcacc30de69"},"cell_type":"code","source":"data2.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1ebe4bd9306175b09a857b7b6b3b31a86dec7818"},"cell_type":"code","source":"print(data2['authorized_flag'].value_counts(dropna =False))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8b6ce1636c7d3989b46586dbf801a1b876874ca7"},"cell_type":"code","source":"print(data2['city_id'].value_counts(dropna =False))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"42d0a2c2570544ee1e3948a11cbfd0170076b3e3"},"cell_type":"code","source":"print(data2['card_id'].value_counts(dropna =False))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"dd82c79fad7a7007dce6635739ecf06ccfcce084"},"cell_type":"code","source":"print(data2['category_3'].value_counts(dropna =False))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"68a0b49c6d17bcdd8dc9ba46b3c4ce4edb3eb72e"},"cell_type":"code","source":"data1.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"20f482f008c1deb1205b830e938afa362064a458"},"cell_type":"code","source":"data2.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"18afc3cecc7da5daefb8d158229305173eb1f79b"},"cell_type":"code","source":"data2.boxplot(column='purchase_amount')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d983a6a9b7cb7a618de10f53f7615e3201fc4074"},"cell_type":"code","source":"data_new1 = data1.head()\ndata_new1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1bf3bcf24f182c42092652cb3c723ab0f07932b4"},"cell_type":"code","source":"melted1 = pd.melt(frame = data_new1,id_vars = 'merchant_id',value_vars = ['merchant_category_id','subsector_id'])\nmelted1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ad64b80fa69b18739b05e2ed212edfaa21c71e4a"},"cell_type":"code","source":"data_new2 = data2.head()\ndata_new2","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f267cedb00257f1049936c41e6cbe4178869f429"},"cell_type":"code","source":"melted2 = pd.melt(frame = data_new2,id_vars = 'card_id',value_vars = ['purchase_amount','installments'])\nmelted2","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c4d321bc09c1bd8060c67dc9882fd1e15af11931"},"cell_type":"code","source":"# Reverse of melting (pivoting_data)\nmelted1.pivot(index = 'merchant_id',columns = 'variable',values = 'value')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ee681433e5b142a2b261420b8c2956b0f05668d8"},"cell_type":"code","source":"# concetenating data \nconc_data = data1.head()\nconc_data1 = data1.tail()\nconc_data_row = pd.concat([conc_data,conc_data1],axis = 0,ignore_index = False)\nconc_data_row","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cea4fd7174bc830bb827068a1e30f24120065bc5"},"cell_type":"code","source":"data_0 = data1['merchant_category_id'].head()\ndata_1 = data1['subsector_id'].head()\nconc_data_col = pd.concat([data_0,data_1],axis = 1,ignore_index = False)\nconc_data_col","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"74ed7cad342fb5cd1dd91f959736c813911d96cb"},"cell_type":"code","source":"data1['avg_sales_lag3'].fillna('empty',inplace = True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4ec1f92ca56f7740c9c753b09d6d30359835e79b"},"cell_type":"code","source":"data1.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bc23981214c0a15a0ccce580c6ac07d70c034458"},"cell_type":"code","source":"data1['avg_sales_lag6'].fillna(0.0,inplace = True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6d41bc032c2a8328e63e644d7b60501022a4efcf"},"cell_type":"code","source":"assert data1['avg_sales_lag6'].notnull().all()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"42df3d5ca026af33f046cf62ae22adb139e0e0ea"},"cell_type":"code","source":"data1['avg_sales_lag6'] = data1['avg_sales_lag6'].astype('int64')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c7ccedda400d3fba30f13e10c1ef5204ae0e684b"},"cell_type":"code","source":"data1.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a5b977c028699d8aaf6f46bd168f772bf6b3fcbe"},"cell_type":"code","source":"data1.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"16c0d645701dab2fad1cc6581c240fca444bdf54"},"cell_type":"code","source":"data2.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"aaca9c92d1f79a22a50357069f55e8192e7f8700"},"cell_type":"code","source":"data1['category_1'] = data1['category_1'].astype(\"category\")","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}