{"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-07-07T01:29:26.580758Z","iopub.execute_input":"2022-07-07T01:29:26.581797Z","iopub.status.idle":"2022-07-07T01:29:26.592605Z","shell.execute_reply.started":"2022-07-07T01:29:26.581757Z","shell.execute_reply":"2022-07-07T01:29:26.591622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# mortgage rate data, changed column names and dropped empty columns\nroot = '/kaggle/input/mortgage-rate/'\nmortgageData = pd.read_csv(os.path.join(root, '34100145.csv'))\nmortgageData = mortgageData.drop(columns=['GEO', 'DGUID', 'UOM', 'UOM_ID', 'SCALAR_FACTOR', 'SCALAR_ID', 'VECTOR', 'COORDINATE', 'STATUS', 'SYMBOL', 'TERMINATED', 'DECIMALS'])\nmortgageData = mortgageData.rename(columns={'REF_DATE': 'Date', 'VALUE': 'Mortgage Rate'})","metadata":{"execution":{"iopub.status.busy":"2022-07-07T01:29:34.712225Z","iopub.execute_input":"2022-07-07T01:29:34.712626Z","iopub.status.idle":"2022-07-07T01:29:34.730223Z","shell.execute_reply.started":"2022-07-07T01:29:34.712593Z","shell.execute_reply":"2022-07-07T01:29:34.729155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# interest rate data, changed column names\nroot = '/kaggle/input/interest-rate/'\ninterestData = pd.read_csv(os.path.join(root, 'IRSTCB01CAM156N.csv'))\ninterestData = interestData.rename(columns={'DATE': 'Date', 'IRSTCB01CAM156N': 'Interest Rate'})","metadata":{"execution":{"iopub.status.busy":"2022-07-07T01:29:37.768862Z","iopub.execute_input":"2022-07-07T01:29:37.769258Z","iopub.status.idle":"2022-07-07T01:29:37.779956Z","shell.execute_reply.started":"2022-07-07T01:29:37.769228Z","shell.execute_reply":"2022-07-07T01:29:37.778022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# merged dataframes together and aligned by date\nrateData = pd.concat([interestData, mortgageData], axis=0)\nrateData['Date'] = rateData['Date'].str[:7]\naggFunc = {'Mortgage Rate': 'sum', 'Interest Rate': 'sum'}\nrateData = rateData.groupby(rateData['Date']).aggregate(aggFunc)\nrateData = rateData.loc[:, (rateData != '0.00').any(axis=0)]\nrateData","metadata":{"execution":{"iopub.status.busy":"2022-07-07T01:29:39.814629Z","iopub.execute_input":"2022-07-07T01:29:39.815217Z","iopub.status.idle":"2022-07-07T01:29:39.880034Z","shell.execute_reply.started":"2022-07-07T01:29:39.815170Z","shell.execute_reply":"2022-07-07T01:29:39.878807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rateData.to_csv('interest_mortgage_rate_data')","metadata":{"execution":{"iopub.status.busy":"2022-07-07T01:33:20.698013Z","iopub.execute_input":"2022-07-07T01:33:20.698562Z","iopub.status.idle":"2022-07-07T01:33:20.709196Z","shell.execute_reply.started":"2022-07-07T01:33:20.698519Z","shell.execute_reply":"2022-07-07T01:33:20.707465Z"},"trusted":true},"execution_count":null,"outputs":[]}]}