{"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\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\nimport plotly.graph_objects as go\nfrom plotly.offline import init_notebook_mode, iplot\ninit_notebook_mode(connected=True)\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-07-10T13:09:05.675304Z","iopub.execute_input":"2022-07-10T13:09:05.676064Z","iopub.status.idle":"2022-07-10T13:09:05.792543Z","shell.execute_reply.started":"2022-07-10T13:09:05.675947Z","shell.execute_reply":"2022-07-10T13:09:05.791386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cpi_df = pd.read_csv('../input/housing-affordability-in-canada/CPI-inflation-by-region-1914-202.csv')\ncpi_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T13:11:26.515796Z","iopub.execute_input":"2022-07-10T13:11:26.516215Z","iopub.status.idle":"2022-07-10T13:11:26.771311Z","shell.execute_reply.started":"2022-07-10T13:11:26.516178Z","shell.execute_reply":"2022-07-10T13:11:26.769960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cpi_df.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T13:11:30.330395Z","iopub.execute_input":"2022-07-10T13:11:30.330780Z","iopub.status.idle":"2022-07-10T13:11:30.382614Z","shell.execute_reply.started":"2022-07-10T13:11:30.330750Z","shell.execute_reply":"2022-07-10T13:11:30.381454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"How is the demand and supply for the housing looks like?\nConsumer Price Index\nThe Consumer Price Index (CPI) is a measure of the average change overtime in the prices paid by urban consumers for a market basket of consumer goods and services.\n\nThere is an upward change in the CPI of all the provinces, this means there has been an increase in the average change in prices over time. This eventually leads to adjustments in the cost of living and income (presumably so that income is adjusted to meet a higher cost of living).","metadata":{}},{"cell_type":"code","source":"import seaborn as sns\nimport plotly.express as px","metadata":{"execution":{"iopub.status.busy":"2022-07-10T13:21:38.176368Z","iopub.execute_input":"2022-07-10T13:21:38.176765Z","iopub.status.idle":"2022-07-10T13:21:38.740916Z","shell.execute_reply.started":"2022-07-10T13:21:38.176733Z","shell.execute_reply":"2022-07-10T13:21:38.739718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(cpi_df, x=\"REF_DATE\", y=\"CPI\", color=\"GEO\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T13:16:10.573163Z","iopub.execute_input":"2022-07-10T13:16:10.573543Z","iopub.status.idle":"2022-07-10T13:16:12.438817Z","shell.execute_reply.started":"2022-07-10T13:16:10.573512Z","shell.execute_reply":"2022-07-10T13:16:12.436108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"How is the demand and supply for the housing looks like? <br>\n**Consumer Price Index**\nThe Consumer Price Index (CPI) is a measure of the average change overtime in the prices paid by urban consumers for a market basket of consumer goods and services.\n\n**There is an upward change in the CPI of all the provinces over years**, this means there has been an increase in the average change in prices over time. This eventually leads to adjustments in the cost of living and income (presumably so that income is adjusted to meet a higher cost of living).\n\n**Also in some regions like Alberta, saskatchewan is growing fast in terms of housing supply may be due to immigration**","metadata":{}},{"cell_type":"code","source":"sns.distplot(cpi_df[\"CPI\"],kde=False,bins=100)\n#most of the provinces in canada have CPI = 100","metadata":{"execution":{"iopub.status.busy":"2022-07-10T13:31:58.889264Z","iopub.execute_input":"2022-07-10T13:31:58.889664Z","iopub.status.idle":"2022-07-10T13:31:59.239615Z","shell.execute_reply.started":"2022-07-10T13:31:58.889632Z","shell.execute_reply":"2022-07-10T13:31:59.238413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sns.boxplot(x=\"REF_DATE\", y=\"CPI\" ,data=cpi_df,hue=\"GEO\")\nsns.jointplot(x=\"REF_DATE\",y=\"CPI\" ,data =cpi_df,kind=\"scatter\")","metadata":{"execution":{"iopub.status.busy":"2022-07-10T13:51:11.205541Z","iopub.execute_input":"2022-07-10T13:51:11.205942Z","iopub.status.idle":"2022-07-10T13:51:12.508274Z","shell.execute_reply.started":"2022-07-10T13:51:11.205907Z","shell.execute_reply":"2022-07-10T13:51:12.507072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sns.jointplot(y=\"Products and product groups\",x=\"CPI\" ,data =cpi_df,kind=\"scatter\")","metadata":{"execution":{"iopub.status.busy":"2022-07-10T14:01:04.406542Z","iopub.execute_input":"2022-07-10T14:01:04.406907Z","iopub.status.idle":"2022-07-10T14:01:04.411790Z","shell.execute_reply.started":"2022-07-10T14:01:04.406877Z","shell.execute_reply":"2022-07-10T14:01:04.410695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(cpi_df, x=\"Products and product groups\", y=\"REF_DATE\", color=\"CPI\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T13:53:21.789909Z","iopub.execute_input":"2022-07-10T13:53:21.790374Z","iopub.status.idle":"2022-07-10T13:53:22.838151Z","shell.execute_reply.started":"2022-07-10T13:53:21.790327Z","shell.execute_reply":"2022-07-10T13:53:22.836049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Here we can see that CPI of Fresh Milk,Rent, Oranges(Fruits) and leasing a vehicles have increased that directly indicates fast growth in terms of housing supply, population or immigration**","metadata":{}},{"cell_type":"code","source":"hpi_df = pd.read_csv('../input/housing-affordability-in-canada/HPI 1981-2022 federal and provincial.csv')\nhpi_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T14:14:35.393635Z","iopub.execute_input":"2022-07-10T14:14:35.394028Z","iopub.status.idle":"2022-07-10T14:14:35.435198Z","shell.execute_reply.started":"2022-07-10T14:14:35.393984Z","shell.execute_reply":"2022-07-10T14:14:35.433984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"hpi_df.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-10T14:14:50.446547Z","iopub.execute_input":"2022-07-10T14:14:50.446903Z","iopub.status.idle":"2022-07-10T14:14:50.454249Z","shell.execute_reply.started":"2022-07-10T14:14:50.446875Z","shell.execute_reply":"2022-07-10T14:14:50.453077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"hpi_df.T","metadata":{"execution":{"iopub.status.busy":"2022-07-10T14:15:05.113752Z","iopub.execute_input":"2022-07-10T14:15:05.114167Z","iopub.status.idle":"2022-07-10T14:15:05.198767Z","shell.execute_reply.started":"2022-07-10T14:15:05.114132Z","shell.execute_reply":"2022-07-10T14:15:05.197724Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Population growth","metadata":{}},{"cell_type":"code","source":"i_and_m_df = pd.read_csv('../input/housing-affordability-in-canada/Interest and mortgage rates 1951-2022.csv')\ni_and_m_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T14:10:38.438912Z","iopub.execute_input":"2022-07-10T14:10:38.439919Z","iopub.status.idle":"2022-07-10T14:10:38.458929Z","shell.execute_reply.started":"2022-07-10T14:10:38.439874Z","shell.execute_reply":"2022-07-10T14:10:38.458077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(i_and_m_df, x=\"Mortgage Rate\", y=\"Date\", color=\"Interest Rate\")\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-10T14:10:39.671777Z","iopub.execute_input":"2022-07-10T14:10:39.672900Z","iopub.status.idle":"2022-07-10T14:10:39.765119Z","shell.execute_reply.started":"2022-07-10T14:10:39.672848Z","shell.execute_reply":"2022-07-10T14:10:39.764055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Mortage rates reduces maybe due to covid 19 <br>\nOver time, as you pay down the principal, you owe less interest each month, because your loan balance is lower. So, more of your monthly payment goes to paying down the principal.<br>\nAlso, Slight increase tends also seen.**","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}