{"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":"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\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-05-10T03:39:17.749683Z","iopub.execute_input":"2022-05-10T03:39:17.750393Z","iopub.status.idle":"2022-05-10T03:39:17.783481Z","shell.execute_reply.started":"2022-05-10T03:39:17.750257Z","shell.execute_reply":"2022-05-10T03:39:17.782682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dtype = {\n    'Semana': 'int8',\n    'Agencia_ID': 'int16',\n    'Canal_ID': 'int8',\n    'Ruta_SAK': 'int16',\n    'Cliente_ID': 'int32',\n    'Producto_ID': 'int32',\n    'Venta_uni_hoy': 'int16',\n    'Venta_hoy': 'float32',\n    'Dev_uni_proxima': 'int32',\n    'Dev_proxima': 'float32',\n    'Demanda_uni_equil': 'int16',\n}\ndf = pd.read_csv('../input/grupo-bimbo-inventory-demand/train.csv.zip', dtype=dtype)","metadata":{"execution":{"iopub.status.busy":"2022-05-10T03:39:17.785134Z","iopub.execute_input":"2022-05-10T03:39:17.786189Z","iopub.status.idle":"2022-05-10T03:40:43.110135Z","shell.execute_reply.started":"2022-05-10T03:39:17.786134Z","shell.execute_reply":"2022-05-10T03:40:43.109048Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-05-10T03:40:43.111536Z","iopub.execute_input":"2022-05-10T03:40:43.111772Z","iopub.status.idle":"2022-05-10T03:40:43.142012Z","shell.execute_reply.started":"2022-05-10T03:40:43.111744Z","shell.execute_reply":"2022-05-10T03:40:43.140749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-10T03:40:43.143647Z","iopub.execute_input":"2022-05-10T03:40:43.143945Z","iopub.status.idle":"2022-05-10T03:40:43.175140Z","shell.execute_reply.started":"2022-05-10T03:40:43.143909Z","shell.execute_reply":"2022-05-10T03:40:43.174203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv('../input/grupo-bimbo-inventory-demand/train.csv.zip',# usecols = ['Semana', 'Producto_ID'] + cols,\n                           dtype  = {'Semana': 'int8',\n    'Agencia_ID': 'int16',\n    'Canal_ID': 'int8',\n    'Ruta_SAK': 'int16',\n    'Cliente_ID': 'int32',\n    'Producto_ID': 'int32',\n    'Venta_uni_hoy': 'int16',\n    'Venta_hoy': 'float32',\n    'Dev_uni_proxima': 'int32',\n    'Dev_proxima': 'float32',\n    'Demanda_uni_equil': 'int16',})\ndef get_product_agg(cols):\n    agg  = df_train.groupby(['Semana', 'Producto_ID'], as_index=False).agg(['count','sum', 'min', 'max','median','mean'])\n    agg.columns  =  ['_'.join(col).strip() for col in agg.columns.values]\n#     del(df_train)\n    return agg\n\nagg1 = get_product_agg(['Demanda_uni_equil','Dev_uni_proxima'])","metadata":{"execution":{"iopub.status.busy":"2022-05-10T03:53:06.216651Z","iopub.execute_input":"2022-05-10T03:53:06.217578Z","iopub.status.idle":"2022-05-10T03:55:12.082189Z","shell.execute_reply.started":"2022-05-10T03:53:06.217529Z","shell.execute_reply":"2022-05-10T03:55:12.081024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"agg1.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-10T03:55:12.084266Z","iopub.execute_input":"2022-05-10T03:55:12.084997Z","iopub.status.idle":"2022-05-10T03:55:12.118800Z","shell.execute_reply.started":"2022-05-10T03:55:12.084953Z","shell.execute_reply":"2022-05-10T03:55:12.117861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"products  =  pd.read_csv(\"../input/grupo-bimbo-inventory-demand/producto_tabla.csv.zip\")\nproducts['short_name'] = products.NombreProducto.str.extract('^(\\D*)', expand=False)\nproducts['brand'] = products.NombreProducto.str.extract('^.+\\s(\\D+) \\d+$', expand=False)\nw = products.NombreProducto.str.extract('(\\d+)(Kg|g)', expand=True)\nproducts['weight'] = w[0].astype('float')*w[1].map({'Kg':1000, 'g':1})\nproducts['pieces'] =  products.NombreProducto.str.extract('(\\d+)p ', expand=False).astype('float')\nproducts.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-10T03:55:12.120399Z","iopub.execute_input":"2022-05-10T03:55:12.120643Z","iopub.status.idle":"2022-05-10T03:55:12.178995Z","shell.execute_reply.started":"2022-05-10T03:55:12.120612Z","shell.execute_reply":"2022-05-10T03:55:12.177888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"products.short_name.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-05-10T03:55:12.180593Z","iopub.execute_input":"2022-05-10T03:55:12.180906Z","iopub.status.idle":"2022-05-10T03:55:12.192261Z","shell.execute_reply.started":"2022-05-10T03:55:12.180861Z","shell.execute_reply":"2022-05-10T03:55:12.191143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.Semana.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-05-10T04:02:41.029027Z","iopub.execute_input":"2022-05-10T04:02:41.030114Z","iopub.status.idle":"2022-05-10T04:02:41.360353Z","shell.execute_reply.started":"2022-05-10T04:02:41.030061Z","shell.execute_reply":"2022-05-10T04:02:41.359055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.groupby(['Semana','Agencia_ID','Producto_ID']).sum('Demanda_uni_equil')","metadata":{"execution":{"iopub.status.busy":"2022-05-10T04:18:21.290325Z","iopub.execute_input":"2022-05-10T04:18:21.290669Z","iopub.status.idle":"2022-05-10T04:18:33.297591Z","shell.execute_reply.started":"2022-05-10T04:18:21.290634Z","shell.execute_reply":"2022-05-10T04:18:33.296550Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.Agencia_ID.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-05-10T04:14:57.379720Z","iopub.execute_input":"2022-05-10T04:14:57.380999Z","iopub.status.idle":"2022-05-10T04:14:57.728775Z","shell.execute_reply.started":"2022-05-10T04:14:57.380934Z","shell.execute_reply":"2022-05-10T04:14:57.727393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}