{"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":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport matplotlib.pyplot as plt\nfrom learntools.time_series.utils import seasonal_plot\n\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-19T20:59:23.521475Z","iopub.execute_input":"2022-07-19T20:59:23.521864Z","iopub.status.idle":"2022-07-19T20:59:23.529237Z","shell.execute_reply.started":"2022-07-19T20:59:23.521819Z","shell.execute_reply":"2022-07-19T20:59:23.528417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Leemos el archivo **stores.csv** con el comando **pd.read_csv** y lo asignamos al dataframe **stores**","metadata":{}},{"cell_type":"code","source":"stores = pd.read_csv('/kaggle/input/store-sales-time-series-forecasting/stores.csv')\noil = pd.read_csv('/kaggle/input/store-sales-time-series-forecasting/oil.csv')\ntransactions = pd.read_csv('/kaggle/input/store-sales-time-series-forecasting/transactions.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-19T20:59:53.923890Z","iopub.execute_input":"2022-07-19T20:59:53.924285Z","iopub.status.idle":"2022-07-19T20:59:53.972203Z","shell.execute_reply.started":"2022-07-19T20:59:53.924253Z","shell.execute_reply":"2022-07-19T20:59:53.971166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Visualizamos los primeros 5 registros del dataframe con el comando **head()**","metadata":{}},{"cell_type":"code","source":"stores.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-19T20:16:07.781029Z","iopub.execute_input":"2022-07-19T20:16:07.781447Z","iopub.status.idle":"2022-07-19T20:16:07.802709Z","shell.execute_reply.started":"2022-07-19T20:16:07.781417Z","shell.execute_reply":"2022-07-19T20:16:07.801914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all = transactions.merge(stores, how=\"left\", on=\"store_nbr\")","metadata":{"execution":{"iopub.status.busy":"2022-07-19T21:00:27.338951Z","iopub.execute_input":"2022-07-19T21:00:27.339342Z","iopub.status.idle":"2022-07-19T21:00:27.358067Z","shell.execute_reply.started":"2022-07-19T21:00:27.339311Z","shell.execute_reply":"2022-07-19T21:00:27.357150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all = transactions.merge(oil, how=\"left\", on=\"date\")","metadata":{"execution":{"iopub.status.busy":"2022-07-19T21:00:23.693617Z","iopub.execute_input":"2022-07-19T21:00:23.694037Z","iopub.status.idle":"2022-07-19T21:00:23.717745Z","shell.execute_reply.started":"2022-07-19T21:00:23.694004Z","shell.execute_reply":"2022-07-19T21:00:23.716833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all.head(1)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T20:16:51.820219Z","iopub.execute_input":"2022-07-19T20:16:51.820680Z","iopub.status.idle":"2022-07-19T20:16:51.831878Z","shell.execute_reply.started":"2022-07-19T20:16:51.820643Z","shell.execute_reply":"2022-07-19T20:16:51.831031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all['date'] =  pd.to_datetime(all['date'], infer_datetime_format=True)\nall[\"date\"] = all[\"date\"].dt.to_period('D')","metadata":{"execution":{"iopub.status.busy":"2022-07-19T21:00:29.501538Z","iopub.execute_input":"2022-07-19T21:00:29.501962Z","iopub.status.idle":"2022-07-19T21:00:29.537564Z","shell.execute_reply.started":"2022-07-19T21:00:29.501926Z","shell.execute_reply":"2022-07-19T21:00:29.536208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all.head(1)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T21:00:31.430287Z","iopub.execute_input":"2022-07-19T21:00:31.430787Z","iopub.status.idle":"2022-07-19T21:00:31.444727Z","shell.execute_reply.started":"2022-07-19T21:00:31.430748Z","shell.execute_reply":"2022-07-19T21:00:31.443351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = (\n    all\n    .groupby('date').mean()\n    .squeeze()\n)\n\nX[\"day\"] = X.index.dayofweek\nX[\"week\"] = X.index.week\n\nX[\"dayofyear\"] = X.index.dayofyear\nX[\"year\"] = X.index.year\n\nX[\"dayofmonth\"] = X.index.day\nX[\"month\"] = X.index.month\n\nfig, (ax0, ax1, ax2) = plt.subplots(3, 1, figsize=(15, 10))\n\nseasonal_plot(X, y=\"transactions\", period=\"week\", freq=\"day\", ax=ax0)\nseasonal_plot(X, y=\"transactions\", period=\"month\", freq=\"dayofmonth\", ax=ax1)\nseasonal_plot(X, y=\"transactions\", period=\"year\", freq=\"dayofyear\", ax=ax2)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T22:23:23.055638Z","iopub.execute_input":"2022-07-19T22:23:23.056080Z","iopub.status.idle":"2022-07-19T22:23:44.929800Z","shell.execute_reply.started":"2022-07-19T22:23:23.056044Z","shell.execute_reply":"2022-07-19T22:23:44.928955Z"},"trusted":true},"execution_count":null,"outputs":[]}]}