{ "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 = \"sales/\"\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": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "processing Metro_mean_sale_to_list_uc_sfrcondo_sm_month.csv\n", "processing Metro_median_sale_to_list_uc_sfrcondo_week.csv\n", "processing Metro_median_sale_price_uc_sfr_week.csv\n", "processing Metro_pct_sold_below_list_uc_sfrcondo_sm_month.csv\n", "processing Metro_median_sale_price_uc_sfr_sm_sa_week.csv\n", "processing Metro_pct_sold_below_list_uc_sfrcondo_month.csv\n", "processing Metro_median_sale_price_uc_sfrcondo_sm_week.csv\n", "processing Metro_pct_sold_below_list_uc_sfrcondo_sm_week.csv\n", "processing Metro_median_sale_price_uc_sfr_month.csv\n", "processing Metro_median_sale_to_list_uc_sfrcondo_sm_month.csv\n", "processing Metro_pct_sold_above_list_uc_sfrcondo_month.csv\n", "processing Metro_median_sale_to_list_uc_sfrcondo_sm_week.csv\n", "processing Metro_median_sale_price_uc_sfrcondo_sm_sa_month.csv\n", "processing Metro_sales_count_now_uc_sfrcondo_month.csv\n", "processing Metro_pct_sold_above_list_uc_sfrcondo_week.csv\n", "processing Metro_mean_sale_to_list_uc_sfrcondo_sm_week.csv\n", "processing Metro_median_sale_price_uc_sfrcondo_sm_month.csv\n", "processing Metro_mean_sale_to_list_uc_sfrcondo_week.csv\n", "processing Metro_median_sale_price_uc_sfr_sm_month.csv\n", "processing Metro_median_sale_to_list_uc_sfrcondo_month.csv\n", "processing Metro_median_sale_price_uc_sfrcondo_sm_sa_week.csv\n", "processing Metro_pct_sold_below_list_uc_sfrcondo_week.csv\n", "processing Metro_median_sale_price_uc_sfrcondo_week.csv\n", "processing Metro_mean_sale_to_list_uc_sfrcondo_month.csv\n", "processing Metro_pct_sold_above_list_uc_sfrcondo_sm_week.csv\n", "processing Metro_median_sale_price_uc_sfr_sm_week.csv\n", "processing Metro_median_sale_price_uc_sfrcondo_month.csv\n", "processing Metro_pct_sold_above_list_uc_sfrcondo_sm_month.csv\n" ] }, { "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \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 TypeDateMean Sale to List Ratio (Smoothed)Median Sale to List RatioMedian Sale Price% Sold Below List (Smoothed)Median Sale Price (Smoothed) (Seasonally Adjusted)% Sold Below ListMedian Sale Price (Smoothed)Median Sale to List Ratio (Smoothed)% Sold Above ListNowcastMean Sale to List Ratio% Sold Above List (Smoothed)
01020010United StatescountryNaNSFR2008-02-02NaNNaN172000.0NaNNaNNaNNaNNaNNaNNaNNaNNaN
11020010United StatescountryNaNSFR2008-02-09NaNNaN165400.0NaNNaNNaNNaNNaNNaNNaNNaNNaN
21020010United StatescountryNaNSFR2008-02-16NaNNaN168000.0NaNNaNNaNNaNNaNNaNNaNNaNNaN
31020010United StatescountryNaNSFR2008-02-23NaNNaN165000.0NaNNaNNaN167600.0NaNNaNNaNNaNNaN
41020010United StatescountryNaNSFR2008-02-29NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
............................................................
504603845167296Ottawa, ILmsaILall homes2023-07-310.976219NaNNaN0.554969127574.00.491379133500.00.9851720.312332NaN0.9792270.312332
504604845167296Ottawa, ILmsaILall homes2023-08-310.971893NaNNaN0.541090125089.00.602041131833.00.9873830.294778NaN0.9592610.294778
504605845167296Ottawa, ILmsaILall homes2023-09-300.968028NaNNaN0.531140127199.00.500000132333.00.9910720.285128NaN0.9655950.285128
504606845167296Ottawa, ILmsaILall homes2023-10-310.962485NaNNaN0.558836131159.00.574468134667.00.9856570.272350NaN0.9625990.272350
504607845167296Ottawa, ILmsaILall homes2023-11-300.967126NaNNaN0.539226129291.00.543210131000.00.9908860.280538NaN0.9731840.280538
\n", "

504608 rows × 19 columns

\n", "
" ], "text/plain": [ " RegionID SizeRank RegionName RegionType StateName Home Type \\\n", "0 102001 0 United States country NaN SFR \n", "1 102001 0 United States country NaN SFR \n", "2 102001 0 United States country NaN SFR \n", "3 102001 0 United States country NaN SFR \n", "4 102001 0 United States country NaN SFR \n", "... ... ... ... ... ... ... \n", "504603 845167 296 Ottawa, IL msa IL all homes \n", "504604 845167 296 Ottawa, IL msa IL all homes \n", "504605 845167 296 Ottawa, IL msa IL all homes \n", "504606 845167 296 Ottawa, IL msa IL all homes \n", "504607 845167 296 Ottawa, IL msa IL all homes \n", "\n", " Date Mean Sale to List Ratio (Smoothed) \\\n", "0 2008-02-02 NaN \n", "1 2008-02-09 NaN \n", "2 2008-02-16 NaN \n", "3 2008-02-23 NaN \n", "4 2008-02-29 NaN \n", "... ... ... \n", "504603 2023-07-31 0.976219 \n", "504604 2023-08-31 0.971893 \n", "504605 2023-09-30 0.968028 \n", "504606 2023-10-31 0.962485 \n", "504607 2023-11-30 0.967126 \n", "\n", " Median Sale to List Ratio Median Sale Price \\\n", "0 NaN 172000.0 \n", "1 NaN 165400.0 \n", "2 NaN 168000.0 \n", "3 NaN 165000.0 \n", "4 NaN NaN \n", "... ... ... \n", "504603 NaN NaN \n", "504604 NaN NaN \n", "504605 NaN NaN \n", "504606 NaN NaN \n", "504607 NaN NaN \n", "\n", " % Sold Below List (Smoothed) \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "504603 0.554969 \n", "504604 0.541090 \n", "504605 0.531140 \n", "504606 0.558836 \n", "504607 0.539226 \n", "\n", " Median Sale Price (Smoothed) (Seasonally Adjusted) % Sold Below List \\\n", "0 NaN NaN \n", "1 NaN NaN \n", "2 NaN NaN \n", "3 NaN NaN \n", "4 NaN NaN \n", "... ... ... \n", "504603 127574.0 0.491379 \n", "504604 125089.0 0.602041 \n", "504605 127199.0 0.500000 \n", "504606 131159.0 0.574468 \n", "504607 129291.0 0.543210 \n", "\n", " Median Sale Price (Smoothed) Median Sale to List Ratio (Smoothed) \\\n", "0 NaN NaN \n", "1 NaN NaN \n", "2 NaN NaN \n", "3 167600.0 NaN \n", "4 NaN NaN \n", "... ... ... \n", "504603 133500.0 0.985172 \n", "504604 131833.0 0.987383 \n", "504605 132333.0 0.991072 \n", "504606 134667.0 0.985657 \n", "504607 131000.0 0.990886 \n", "\n", " % Sold Above List Nowcast Mean Sale to List Ratio \\\n", "0 NaN NaN NaN \n", "1 NaN NaN NaN \n", "2 NaN NaN NaN \n", "3 NaN NaN NaN \n", "4 NaN NaN NaN \n", "... ... ... ... \n", "504603 0.312332 NaN 0.979227 \n", "504604 0.294778 NaN 0.959261 \n", "504605 0.285128 NaN 0.965595 \n", "504606 0.272350 NaN 0.962599 \n", "504607 0.280538 NaN 0.973184 \n", "\n", " % Sold Above List (Smoothed) \n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "504603 0.312332 \n", "504604 0.294778 \n", "504605 0.285128 \n", "504606 0.272350 \n", "504607 0.280538 \n", "\n", "[504608 rows x 19 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# base cols RegionID,SizeRank,RegionName,RegionType,StateName\n", "\n", "exclude_columns = [\n", " \"RegionID\",\n", " \"SizeRank\",\n", " \"RegionName\",\n", " \"RegionType\",\n", " \"StateName\",\n", " \"Home Type\",\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", "\n", " # ignore monthly data for now since it is redundant\n", " if \"monthly\" in filename:\n", " continue\n", "\n", " if \"_sfrcondo_\" in filename:\n", " cur_df[\"Home Type\"] = \"all homes\"\n", " elif \"_sfr_\" in filename:\n", " cur_df[\"Home Type\"] = \"SFR\"\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", " if \"_median_sale_to_list_\" in filename:\n", " col_name = \"Median Sale to List Ratio\"\n", " if smoothed:\n", " col_name += \" (Smoothed)\"\n", " if seasonally_adjusted:\n", " col_name += \" (Seasonally Adjusted)\"\n", "\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", "\n", " elif \"_mean_sale_to_list_\" in filename:\n", " col_name = \"Mean Sale to List Ratio\"\n", " if smoothed:\n", " col_name += \" (Smoothed)\"\n", " if seasonally_adjusted:\n", " col_name += \" (Seasonally Adjusted)\"\n", "\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", "\n", " elif \"_median_sale_price_\" in filename:\n", " col_name = \"Median Sale Price\"\n", " if smoothed:\n", " col_name += \" (Smoothed)\"\n", " if seasonally_adjusted:\n", " col_name += \" (Seasonally Adjusted)\"\n", "\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", "\n", " elif \"_pct_sold_above_list_\" in filename:\n", " col_name = \"% Sold Above List\"\n", " if smoothed:\n", " col_name += \" (Smoothed)\"\n", " if seasonally_adjusted:\n", " col_name += \" (Seasonally Adjusted)\"\n", "\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", "\n", " elif \"_pct_sold_below_list_\" in filename:\n", " col_name = \"% Sold Below List\"\n", " if smoothed:\n", " col_name += \" (Smoothed)\"\n", " if seasonally_adjusted:\n", " col_name += \" (Seasonally Adjusted)\"\n", "\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", "\n", " elif \"_sales_count_now_\" in filename:\n", " col_name = \"Nowcast\"\n", " if smoothed:\n", " col_name += \" (Smoothed)\"\n", " if seasonally_adjusted:\n", " col_name += \" (Seasonally Adjusted)\"\n", "\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", "\n", " data_frames.append(cur_df)\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", "# iterate over rows of combined df and coalesce column values across columns that start with \"Median Sale Price\"\n", "columns_to_coalesce = [\n", " \"Mean Sale to List Ratio (Smoothed)\"\n", " \"Median Sale to List Ratio\"\n", " \"Median Sale Price\"\n", " \"% Sold Below List (Smoothed)\",\n", " \"Median Sale Price (Smoothed) (Seasonally Adjusted)\",\n", " \"% Sold Below List\",\n", " \"Median Sale Price (Smoothed)\",\n", " \"Median Sale to List Ratio (Smoothed)\",\n", " \"% Sold Above List\",\n", " \"Nowcast\",\n", " \"Mean Sale to List Ratio\",\n", " \"% Sold Above List (Smoothed)\",\n", "]\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", "combined_df" ] }, { "cell_type": "code", "execution_count": 6, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \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 TypeStateHome TypeDateMean Sale to List Ratio (Smoothed)Median Sale to List RatioMedian Sale Price% Sold Below List (Smoothed)Median Sale Price (Smoothed) (Seasonally Adjusted)% Sold Below ListMedian Sale Price (Smoothed)Median Sale to List Ratio (Smoothed)% Sold Above ListNowcastMean Sale to List Ratio% Sold Above List (Smoothed)
01020010United StatescountryNaNSFR2008-02-02NaNNaN172000.0NaNNaNNaNNaNNaNNaNNaNNaNNaN
11020010United StatescountryNaNSFR2008-02-09NaNNaN165400.0NaNNaNNaNNaNNaNNaNNaNNaNNaN
21020010United StatescountryNaNSFR2008-02-16NaNNaN168000.0NaNNaNNaNNaNNaNNaNNaNNaNNaN
31020010United StatescountryNaNSFR2008-02-23NaNNaN165000.0NaNNaNNaN167600.0NaNNaNNaNNaNNaN
41020010United StatescountryNaNSFR2008-02-29NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
............................................................
504603845167296Ottawa, ILmsaILall homes2023-07-310.976219NaNNaN0.554969127574.00.491379133500.00.9851720.312332NaN0.9792270.312332
504604845167296Ottawa, ILmsaILall homes2023-08-310.971893NaNNaN0.541090125089.00.602041131833.00.9873830.294778NaN0.9592610.294778
504605845167296Ottawa, ILmsaILall homes2023-09-300.968028NaNNaN0.531140127199.00.500000132333.00.9910720.285128NaN0.9655950.285128
504606845167296Ottawa, ILmsaILall homes2023-10-310.962485NaNNaN0.558836131159.00.574468134667.00.9856570.272350NaN0.9625990.272350
504607845167296Ottawa, ILmsaILall homes2023-11-300.967126NaNNaN0.539226129291.00.543210131000.00.9908860.280538NaN0.9731840.280538
\n", "

504608 rows × 19 columns

\n", "
" ], "text/plain": [ " Region ID Size Rank Region Region Type State Home Type \\\n", "0 102001 0 United States country NaN SFR \n", "1 102001 0 United States country NaN SFR \n", "2 102001 0 United States country NaN SFR \n", "3 102001 0 United States country NaN SFR \n", "4 102001 0 United States country NaN SFR \n", "... ... ... ... ... ... ... \n", "504603 845167 296 Ottawa, IL msa IL all homes \n", "504604 845167 296 Ottawa, IL msa IL all homes \n", "504605 845167 296 Ottawa, IL msa IL all homes \n", "504606 845167 296 Ottawa, IL msa IL all homes \n", "504607 845167 296 Ottawa, IL msa IL all homes \n", "\n", " Date Mean Sale to List Ratio (Smoothed) \\\n", "0 2008-02-02 NaN \n", "1 2008-02-09 NaN \n", "2 2008-02-16 NaN \n", "3 2008-02-23 NaN \n", "4 2008-02-29 NaN \n", "... ... ... \n", "504603 2023-07-31 0.976219 \n", "504604 2023-08-31 0.971893 \n", "504605 2023-09-30 0.968028 \n", "504606 2023-10-31 0.962485 \n", "504607 2023-11-30 0.967126 \n", "\n", " Median Sale to List Ratio Median Sale Price \\\n", "0 NaN 172000.0 \n", "1 NaN 165400.0 \n", "2 NaN 168000.0 \n", "3 NaN 165000.0 \n", "4 NaN NaN \n", "... ... ... \n", "504603 NaN NaN \n", "504604 NaN NaN \n", "504605 NaN NaN \n", "504606 NaN NaN \n", "504607 NaN NaN \n", "\n", " % Sold Below List (Smoothed) \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "504603 0.554969 \n", "504604 0.541090 \n", "504605 0.531140 \n", "504606 0.558836 \n", "504607 0.539226 \n", "\n", " Median Sale Price (Smoothed) (Seasonally Adjusted) % Sold Below List \\\n", "0 NaN NaN \n", "1 NaN NaN \n", "2 NaN NaN \n", "3 NaN NaN \n", "4 NaN NaN \n", "... ... ... \n", "504603 127574.0 0.491379 \n", "504604 125089.0 0.602041 \n", "504605 127199.0 0.500000 \n", "504606 131159.0 0.574468 \n", "504607 129291.0 0.543210 \n", "\n", " Median Sale Price (Smoothed) Median Sale to List Ratio (Smoothed) \\\n", "0 NaN NaN \n", "1 NaN NaN \n", "2 NaN NaN \n", "3 167600.0 NaN \n", "4 NaN NaN \n", "... ... ... \n", "504603 133500.0 0.985172 \n", "504604 131833.0 0.987383 \n", "504605 132333.0 0.991072 \n", "504606 134667.0 0.985657 \n", "504607 131000.0 0.990886 \n", "\n", " % Sold Above List Nowcast Mean Sale to List Ratio \\\n", "0 NaN NaN NaN \n", "1 NaN NaN NaN \n", "2 NaN NaN NaN \n", "3 NaN NaN NaN \n", "4 NaN NaN NaN \n", "... ... ... ... \n", "504603 0.312332 NaN 0.979227 \n", "504604 0.294778 NaN 0.959261 \n", "504605 0.285128 NaN 0.965595 \n", "504606 0.272350 NaN 0.962599 \n", "504607 0.280538 NaN 0.973184 \n", "\n", " % Sold Above List (Smoothed) \n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "504603 0.312332 \n", "504604 0.294778 \n", "504605 0.285128 \n", "504606 0.272350 \n", "504607 0.280538 \n", "\n", "[504608 rows x 19 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_df = combined_df\n", "final_df = final_df.rename(\n", " columns={\n", " \"RegionID\": \"Region ID\",\n", " \"SizeRank\": \"Size Rank\",\n", " \"RegionName\": \"Region\",\n", " \"RegionType\": \"Region Type\",\n", " \"StateName\": \"State\",\n", " }\n", ")\n", "\n", "final_df.sort_values(by=[\"Region ID\", \"Home Type\", \"Date\"])" ] }, { "cell_type": "code", "execution_count": 7, "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 }