{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import os" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "DATA_DIR = \"../data\"\n", "PROCESSED_DIR = \"../processed/\"\n", "FACET_DIR = \"rentals/\"\n", "FULL_DATA_DIR_PATH = os.path.join(DATA_DIR, FACET_DIR)\n", "FULL_PROCESSED_DIR_PATH = os.path.join(PROCESSED_DIR, FACET_DIR)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
RegionIDSizeRankRegionNameRegionTypeStateNameHome TypeStateMetroStateCodeFIPSMunicipalCodeFIPSDateRent (Smoothed)CountyNameRent (Smoothed) (Seasonally Adjusted)City
066146Ada CountycountyIDall homes plus multifamilyIDBoise City, ID16.01.02015-01-31927.493763NaN927.493763NaN
166146Ada CountycountyIDall homes plus multifamilyIDBoise City, ID16.01.02015-02-28931.690623NaN931.690623NaN
266146Ada CountycountyIDall homes plus multifamilyIDBoise City, ID16.01.02015-03-31932.568601NaN932.568601NaN
366146Ada CountycountyIDall homes plus multifamilyIDBoise City, ID16.01.02015-04-30933.148134NaN933.148134NaN
466146Ada CountycountyIDall homes plus multifamilyIDBoise City, ID16.01.02015-05-31941.045724NaN941.045724NaN
................................................
1258735857850713Cherry HillcityNJall homes plus multifamilyNaNNaNNaNNaN2023-08-312291.604800Camden County2244.961006NaN
1258736857850713Cherry HillcityNJall homes plus multifamilyNaNNaNNaNNaN2023-09-302296.188906Camden County2254.213172NaN
1258737857850713Cherry HillcityNJall homes plus multifamilyNaNNaNNaNNaN2023-10-312292.270938Camden County2261.540446NaN
1258738857850713Cherry HillcityNJall homes plus multifamilyNaNNaNNaNNaN2023-11-302253.417140Camden County2257.956024NaN
1258739857850713Cherry HillcityNJall homes plus multifamilyNaNNaNNaNNaN2023-12-312280.830303Camden County2280.830303NaN
\n", "

1258740 rows × 15 columns

\n", "
" ], "text/plain": [ " RegionID SizeRank RegionName RegionType StateName \\\n", "0 66 146 Ada County county ID \n", "1 66 146 Ada County county ID \n", "2 66 146 Ada County county ID \n", "3 66 146 Ada County county ID \n", "4 66 146 Ada County county ID \n", "... ... ... ... ... ... \n", "1258735 857850 713 Cherry Hill city NJ \n", "1258736 857850 713 Cherry Hill city NJ \n", "1258737 857850 713 Cherry Hill city NJ \n", "1258738 857850 713 Cherry Hill city NJ \n", "1258739 857850 713 Cherry Hill city NJ \n", "\n", " Home Type State Metro StateCodeFIPS \\\n", "0 all homes plus multifamily ID Boise City, ID 16.0 \n", "1 all homes plus multifamily ID Boise City, ID 16.0 \n", "2 all homes plus multifamily ID Boise City, ID 16.0 \n", "3 all homes plus multifamily ID Boise City, ID 16.0 \n", "4 all homes plus multifamily ID Boise City, ID 16.0 \n", "... ... ... ... ... \n", "1258735 all homes plus multifamily NaN NaN NaN \n", "1258736 all homes plus multifamily NaN NaN NaN \n", "1258737 all homes plus multifamily NaN NaN NaN \n", "1258738 all homes plus multifamily NaN NaN NaN \n", "1258739 all homes plus multifamily NaN NaN NaN \n", "\n", " MunicipalCodeFIPS Date Rent (Smoothed) CountyName \\\n", "0 1.0 2015-01-31 927.493763 NaN \n", "1 1.0 2015-02-28 931.690623 NaN \n", "2 1.0 2015-03-31 932.568601 NaN \n", "3 1.0 2015-04-30 933.148134 NaN \n", "4 1.0 2015-05-31 941.045724 NaN \n", "... ... ... ... ... \n", "1258735 NaN 2023-08-31 2291.604800 Camden County \n", "1258736 NaN 2023-09-30 2296.188906 Camden County \n", "1258737 NaN 2023-10-31 2292.270938 Camden County \n", "1258738 NaN 2023-11-30 2253.417140 Camden County \n", "1258739 NaN 2023-12-31 2280.830303 Camden County \n", "\n", " Rent (Smoothed) (Seasonally Adjusted) City \n", "0 927.493763 NaN \n", "1 931.690623 NaN \n", "2 932.568601 NaN \n", "3 933.148134 NaN \n", "4 941.045724 NaN \n", "... ... ... \n", "1258735 2244.961006 NaN \n", "1258736 2254.213172 NaN \n", "1258737 2261.540446 NaN \n", "1258738 2257.956024 NaN \n", "1258739 2280.830303 NaN \n", "\n", "[1258740 rows x 15 columns]" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# base cols RegionID,SizeRank,RegionName,RegionType,StateName\n", "\n", "\n", "data_frames = []\n", "\n", "for filename in os.listdir(FULL_DATA_DIR_PATH):\n", " if filename.endswith(\".csv\"):\n", " # print(\"processing \" + filename)\n", " cur_df = pd.read_csv(os.path.join(FULL_DATA_DIR_PATH, filename))\n", " exclude_columns = [\n", " \"RegionID\",\n", " \"SizeRank\",\n", " \"RegionName\",\n", " \"RegionType\",\n", " \"StateName\",\n", " \"Home Type\",\n", " ]\n", "\n", " if \"_sfrcondomfr_\" in filename:\n", " cur_df[\"Home Type\"] = \"all homes plus multifamily\"\n", " # change column type to string\n", " cur_df[\"RegionName\"] = cur_df[\"RegionName\"].astype(str)\n", " if \"City\" in filename:\n", " exclude_columns = [\n", " \"RegionID\",\n", " \"SizeRank\",\n", " \"RegionName\",\n", " \"RegionType\",\n", " \"StateName\",\n", " \"Home Type\",\n", " # City Specific\n", " \"State\",\n", " \"Metro\",\n", " \"CountyName\",\n", " ]\n", " elif \"Zip\" in filename:\n", " exclude_columns = [\n", " \"RegionID\",\n", " \"SizeRank\",\n", " \"RegionName\",\n", " \"RegionType\",\n", " \"StateName\",\n", " \"Home Type\",\n", " # Zip Specific\n", " \"State\",\n", " \"City\",\n", " \"Metro\",\n", " \"CountyName\",\n", " ]\n", " elif \"County\" in filename:\n", " exclude_columns = [\n", " \"RegionID\",\n", " \"SizeRank\",\n", " \"RegionName\",\n", " \"RegionType\",\n", " \"StateName\",\n", " \"Home Type\",\n", " # County Specific\n", " \"State\",\n", " \"Metro\",\n", " \"StateCodeFIPS\",\n", " \"MunicipalCodeFIPS\",\n", " ]\n", "\n", " elif \"_sfr_\" in filename:\n", " cur_df[\"Home Type\"] = \"SFR\"\n", " elif \"_mfr_\" in filename:\n", " cur_df[\"Home Type\"] = \"multifamily\"\n", "\n", " # Identify columns to pivot\n", " columns_to_pivot = [col for col in cur_df.columns if col not in exclude_columns]\n", "\n", " smoothed = \"_sm_\" in filename\n", " seasonally_adjusted = \"_sa_\" in filename\n", "\n", " col_name = \"Rent\"\n", " if smoothed:\n", " col_name += \" (Smoothed)\"\n", " if seasonally_adjusted:\n", " col_name += \" (Seasonally Adjusted)\"\n", " cur_df = pd.melt(\n", " cur_df,\n", " id_vars=exclude_columns,\n", " value_vars=columns_to_pivot,\n", " var_name=\"Date\",\n", " value_name=col_name,\n", " )\n", " data_frames.append(cur_df)\n", " # print(filename)\n", "\n", "\n", "def get_combined_df(data_frames):\n", " combined_df = None\n", " if len(data_frames) > 1:\n", " # iterate over dataframes and merge or concat\n", " combined_df = data_frames[0]\n", " for i in range(1, len(data_frames)):\n", " cur_df = data_frames[i]\n", " combined_df = pd.merge(\n", " combined_df,\n", " cur_df,\n", " on=[\n", " \"RegionID\",\n", " \"SizeRank\",\n", " \"RegionName\",\n", " \"RegionType\",\n", " \"StateName\",\n", " \"Home Type\",\n", " \"Date\",\n", " ],\n", " how=\"outer\",\n", " suffixes=(\"\", \"_\" + str(i)),\n", " )\n", " elif len(data_frames) == 1:\n", " combined_df = data_frames[0]\n", "\n", " return combined_df\n", "\n", "\n", "combined_df = get_combined_df(data_frames)\n", "\n", "\n", "# iterate over rows of combined df and coalesce column values across columns that start with \"Median Sale Price\"\n", "columns_to_coalesce = [\"Rent (Smoothed)\", \"Rent (Smoothed) (Seasonally Adjusted)\"]\n", "\n", "for index, row in combined_df.iterrows():\n", " for col in combined_df.columns:\n", " for column_to_coalesce in columns_to_coalesce:\n", " if column_to_coalesce in col and \"_\" in col:\n", " if not pd.isna(row[col]):\n", " combined_df.at[index, column_to_coalesce] = row[col]\n", "\n", "# remove columns with underscores\n", "combined_df = combined_df[[col for col in combined_df.columns if \"_\" not in col]]\n", "\n", "\n", "combined_df" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['RegionID', 'SizeRank', 'RegionName', 'RegionType', 'StateName',\n", " 'Home Type', 'State', 'Metro', 'StateCodeFIPS', 'MunicipalCodeFIPS',\n", " 'Date', 'Rent (Smoothed)', 'CountyName',\n", " 'Rent (Smoothed) (Seasonally Adjusted)', 'City'],\n", " dtype='object')" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "combined_df.columns\n", "# combined_df[\"RegionType\"].unique()\n", "\n", "# combined_df" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
RegionIDSizeRankRegionNameRegionTypeHome TypeStateMetroStateCodeFIPSMunicipalCodeFIPSDateRent (Smoothed)Rent (Smoothed) (Seasonally Adjusted)CityCounty
066146Ada Countycountyall homes plus multifamilyAda CountyBoise City, ID16.01.02015-01-31927.493763927.493763NaNAda County
166146Ada Countycountyall homes plus multifamilyAda CountyBoise City, ID16.01.02015-02-28931.690623931.690623NaNAda County
266146Ada Countycountyall homes plus multifamilyAda CountyBoise City, ID16.01.02015-03-31932.568601932.568601NaNAda County
366146Ada Countycountyall homes plus multifamilyAda CountyBoise City, ID16.01.02015-04-30933.148134933.148134NaNAda County
466146Ada Countycountyall homes plus multifamilyAda CountyBoise City, ID16.01.02015-05-31941.045724941.045724NaNAda County
.............................................
1258735857850713Cherry Hillcityall homes plus multifamilyCamden CountyNaNNaNNaN2023-08-312291.6048002244.961006Cherry HillNaN
1258736857850713Cherry Hillcityall homes plus multifamilyCamden CountyNaNNaNNaN2023-09-302296.1889062254.213172Cherry HillNaN
1258737857850713Cherry Hillcityall homes plus multifamilyCamden CountyNaNNaNNaN2023-10-312292.2709382261.540446Cherry HillNaN
1258738857850713Cherry Hillcityall homes plus multifamilyCamden CountyNaNNaNNaN2023-11-302253.4171402257.956024Cherry HillNaN
1258739857850713Cherry Hillcityall homes plus multifamilyCamden CountyNaNNaNNaN2023-12-312280.8303032280.830303Cherry HillNaN
\n", "

1258740 rows × 14 columns

\n", "
" ], "text/plain": [ " RegionID SizeRank RegionName RegionType \\\n", "0 66 146 Ada County county \n", "1 66 146 Ada County county \n", "2 66 146 Ada County county \n", "3 66 146 Ada County county \n", "4 66 146 Ada County county \n", "... ... ... ... ... \n", "1258735 857850 713 Cherry Hill city \n", "1258736 857850 713 Cherry Hill city \n", "1258737 857850 713 Cherry Hill city \n", "1258738 857850 713 Cherry Hill city \n", "1258739 857850 713 Cherry Hill city \n", "\n", " Home Type State Metro \\\n", "0 all homes plus multifamily Ada County Boise City, ID \n", "1 all homes plus multifamily Ada County Boise City, ID \n", "2 all homes plus multifamily Ada County Boise City, ID \n", "3 all homes plus multifamily Ada County Boise City, ID \n", "4 all homes plus multifamily Ada County Boise City, ID \n", "... ... ... ... \n", "1258735 all homes plus multifamily Camden County NaN \n", "1258736 all homes plus multifamily Camden County NaN \n", "1258737 all homes plus multifamily Camden County NaN \n", "1258738 all homes plus multifamily Camden County NaN \n", "1258739 all homes plus multifamily Camden County NaN \n", "\n", " StateCodeFIPS MunicipalCodeFIPS Date Rent (Smoothed) \\\n", "0 16.0 1.0 2015-01-31 927.493763 \n", "1 16.0 1.0 2015-02-28 931.690623 \n", "2 16.0 1.0 2015-03-31 932.568601 \n", "3 16.0 1.0 2015-04-30 933.148134 \n", "4 16.0 1.0 2015-05-31 941.045724 \n", "... ... ... ... ... \n", "1258735 NaN NaN 2023-08-31 2291.604800 \n", "1258736 NaN NaN 2023-09-30 2296.188906 \n", "1258737 NaN NaN 2023-10-31 2292.270938 \n", "1258738 NaN NaN 2023-11-30 2253.417140 \n", "1258739 NaN NaN 2023-12-31 2280.830303 \n", "\n", " Rent (Smoothed) (Seasonally Adjusted) City County \n", "0 927.493763 NaN Ada County \n", "1 931.690623 NaN Ada County \n", "2 932.568601 NaN Ada County \n", "3 933.148134 NaN Ada County \n", "4 941.045724 NaN Ada County \n", "... ... ... ... \n", "1258735 2244.961006 Cherry Hill NaN \n", "1258736 2254.213172 Cherry Hill NaN \n", "1258737 2261.540446 Cherry Hill NaN \n", "1258738 2257.956024 Cherry Hill NaN \n", "1258739 2280.830303 Cherry Hill NaN \n", "\n", "[1258740 rows x 14 columns]" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_df = combined_df\n", "\n", "for index, row in final_df.iterrows():\n", " if row[\"RegionType\"] == \"city\":\n", " final_df.at[index, \"City\"] = row[\"RegionName\"]\n", " elif row[\"RegionType\"] == \"county\":\n", " final_df.at[index, \"County\"] = row[\"RegionName\"]\n", "\n", "# coalesce State and StateName columns\n", "final_df[\"State\"] = final_df[\"State\"].combine_first(final_df[\"StateName\"])\n", "final_df[\"State\"] = final_df[\"County\"].combine_first(final_df[\"CountyName\"])\n", "\n", "final_df = final_df.drop(columns=[\"StateName\", \"CountyName\"])\n", "final_df" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Region IDSize RankRegionRegion TypeHome TypeStateMetroState Code FIPSMunicipal Code FIPSDateRent (Smoothed)Rent (Smoothed) (Seasonally Adjusted)CityCounty
066146Ada Countycountyall homes plus multifamilyAda CountyBoise City, ID16.01.02015-01-31927.493763927.493763NaNAda County
166146Ada Countycountyall homes plus multifamilyAda CountyBoise City, ID16.01.02015-02-28931.690623931.690623NaNAda County
266146Ada Countycountyall homes plus multifamilyAda CountyBoise City, ID16.01.02015-03-31932.568601932.568601NaNAda County
366146Ada Countycountyall homes plus multifamilyAda CountyBoise City, ID16.01.02015-04-30933.148134933.148134NaNAda County
466146Ada Countycountyall homes plus multifamilyAda CountyBoise City, ID16.01.02015-05-31941.045724941.045724NaNAda County
.............................................
1258735857850713Cherry Hillcityall homes plus multifamilyCamden CountyNaNNaNNaN2023-08-312291.6048002244.961006Cherry HillNaN
1258736857850713Cherry Hillcityall homes plus multifamilyCamden CountyNaNNaNNaN2023-09-302296.1889062254.213172Cherry HillNaN
1258737857850713Cherry Hillcityall homes plus multifamilyCamden CountyNaNNaNNaN2023-10-312292.2709382261.540446Cherry HillNaN
1258738857850713Cherry Hillcityall homes plus multifamilyCamden CountyNaNNaNNaN2023-11-302253.4171402257.956024Cherry HillNaN
1258739857850713Cherry Hillcityall homes plus multifamilyCamden CountyNaNNaNNaN2023-12-312280.8303032280.830303Cherry HillNaN
\n", "

1258740 rows × 14 columns

\n", "
" ], "text/plain": [ " Region ID Size Rank Region Region Type \\\n", "0 66 146 Ada County county \n", "1 66 146 Ada County county \n", "2 66 146 Ada County county \n", "3 66 146 Ada County county \n", "4 66 146 Ada County county \n", "... ... ... ... ... \n", "1258735 857850 713 Cherry Hill city \n", "1258736 857850 713 Cherry Hill city \n", "1258737 857850 713 Cherry Hill city \n", "1258738 857850 713 Cherry Hill city \n", "1258739 857850 713 Cherry Hill city \n", "\n", " Home Type State Metro \\\n", "0 all homes plus multifamily Ada County Boise City, ID \n", "1 all homes plus multifamily Ada County Boise City, ID \n", "2 all homes plus multifamily Ada County Boise City, ID \n", "3 all homes plus multifamily Ada County Boise City, ID \n", "4 all homes plus multifamily Ada County Boise City, ID \n", "... ... ... ... \n", "1258735 all homes plus multifamily Camden County NaN \n", "1258736 all homes plus multifamily Camden County NaN \n", "1258737 all homes plus multifamily Camden County NaN \n", "1258738 all homes plus multifamily Camden County NaN \n", "1258739 all homes plus multifamily Camden County NaN \n", "\n", " State Code FIPS Municipal Code FIPS Date Rent (Smoothed) \\\n", "0 16.0 1.0 2015-01-31 927.493763 \n", "1 16.0 1.0 2015-02-28 931.690623 \n", "2 16.0 1.0 2015-03-31 932.568601 \n", "3 16.0 1.0 2015-04-30 933.148134 \n", "4 16.0 1.0 2015-05-31 941.045724 \n", "... ... ... ... ... \n", "1258735 NaN NaN 2023-08-31 2291.604800 \n", "1258736 NaN NaN 2023-09-30 2296.188906 \n", "1258737 NaN NaN 2023-10-31 2292.270938 \n", "1258738 NaN NaN 2023-11-30 2253.417140 \n", "1258739 NaN NaN 2023-12-31 2280.830303 \n", "\n", " Rent (Smoothed) (Seasonally Adjusted) City County \n", "0 927.493763 NaN Ada County \n", "1 931.690623 NaN Ada County \n", "2 932.568601 NaN Ada County \n", "3 933.148134 NaN Ada County \n", "4 941.045724 NaN Ada County \n", "... ... ... ... \n", "1258735 2244.961006 Cherry Hill NaN \n", "1258736 2254.213172 Cherry Hill NaN \n", "1258737 2261.540446 Cherry Hill NaN \n", "1258738 2257.956024 Cherry Hill NaN \n", "1258739 2280.830303 Cherry Hill NaN \n", "\n", "[1258740 rows x 14 columns]" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_df = final_df.rename(\n", " columns={\n", " \"RegionID\": \"Region ID\",\n", " \"SizeRank\": \"Size Rank\",\n", " \"RegionName\": \"Region\",\n", " \"RegionType\": \"Region Type\",\n", " \"StateCodeFIPS\": \"State Code FIPS\",\n", " \"MunicipalCodeFIPS\": \"Municipal Code FIPS\",\n", " }\n", ")\n", "\n", "final_df" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "if not os.path.exists(FULL_PROCESSED_DIR_PATH):\n", " os.makedirs(FULL_PROCESSED_DIR_PATH)\n", "\n", "final_df.to_json(FULL_PROCESSED_DIR_PATH + \"final.jsonl\", orient=\"records\", lines=True)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" } }, "nbformat": 4, "nbformat_minor": 2 }