{ "cells": [ { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import os\n", "\n", "from helpers import (\n", " get_combined_df,\n", " save_final_df_as_jsonl,\n", " handle_slug_column_mappings,\n", " set_home_type,\n", ")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "DATA_DIR = \"../data\"\n", "PROCESSED_DIR = \"../processed/\"\n", "FACET_DIR = \"days_on_market/\"\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": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "processing Metro_med_listings_price_cut_amt_uc_sfr_month.csv\n", "processing Metro_perc_listings_price_cut_uc_sfr_week.csv\n", "processing Metro_med_listings_price_cut_amt_uc_sfrcondo_month.csv\n", "processing Metro_med_listings_price_cut_amt_uc_sfr_week.csv\n", "processing Metro_med_doz_pending_uc_sfrcondo_month.csv\n", "processing Metro_mean_listings_price_cut_amt_uc_sfr_sm_month.csv\n", "processing Metro_med_listings_price_cut_perc_uc_sfrcondo_sm_month.csv\n", "processing Metro_mean_days_to_close_uc_sfrcondo_week.csv\n", "processing Metro_mean_days_to_close_uc_sfrcondo_month.csv\n", "processing Metro_mean_listings_price_cut_amt_uc_sfrcondo_sm_month.csv\n", "processing Metro_med_listings_price_cut_perc_uc_sfr_week.csv\n", "processing Metro_median_days_to_close_uc_sfrcondo_sm_week.csv\n", "processing Metro_med_listings_price_cut_perc_uc_sfr_sm_week.csv\n", "processing Metro_mean_listings_price_cut_perc_uc_sfrcondo_sm_week.csv\n", "processing Metro_perc_listings_price_cut_uc_sfrcondo_week.csv\n", "processing Metro_med_doz_pending_uc_sfrcondo_sm_month.csv\n", "processing Metro_mean_days_to_close_uc_sfrcondo_sm_week.csv\n", "processing Metro_med_listings_price_cut_perc_uc_sfrcondo_week.csv\n", "processing Metro_mean_listings_price_cut_amt_uc_sfr_week.csv\n", "processing Metro_med_listings_price_cut_perc_uc_sfrcondo_month.csv\n", "processing Metro_mean_doz_pending_uc_sfrcondo_week.csv\n", "processing Metro_mean_listings_price_cut_amt_uc_sfrcondo_week.csv\n", "processing Metro_median_days_to_close_uc_sfrcondo_week.csv\n", "processing Metro_med_listings_price_cut_amt_uc_sfr_sm_month.csv\n", "processing Metro_mean_doz_pending_uc_sfrcondo_sm_month.csv\n", "processing Metro_med_listings_price_cut_perc_uc_sfr_sm_month.csv\n", "processing Metro_perc_listings_price_cut_uc_sfrcondo_sm_week.csv\n", "processing Metro_median_days_to_close_uc_sfrcondo_sm_month.csv\n", "processing Metro_med_listings_price_cut_perc_uc_sfr_month.csv\n", "processing Metro_mean_listings_price_cut_perc_uc_sfrcondo_week.csv\n", "processing Metro_med_listings_price_cut_amt_uc_sfrcondo_week.csv\n", "processing Metro_med_listings_price_cut_amt_uc_sfrcondo_sm_week.csv\n", "processing Metro_mean_days_to_close_uc_sfrcondo_sm_month.csv\n", "processing Metro_med_listings_price_cut_amt_uc_sfr_sm_week.csv\n", "processing Metro_mean_doz_pending_uc_sfrcondo_sm_week.csv\n", "processing Metro_mean_listings_price_cut_amt_uc_sfrcondo_sm_week.csv\n", "processing Metro_mean_listings_price_cut_amt_uc_sfr_sm_week.csv\n", "processing Metro_perc_listings_price_cut_uc_sfrcondo_sm_month.csv\n", "processing Metro_mean_listings_price_cut_amt_uc_sfrcondo_month.csv\n", "processing Metro_med_listings_price_cut_amt_uc_sfrcondo_sm_month.csv\n", "processing Metro_med_doz_pending_uc_sfrcondo_sm_week.csv\n", "processing Metro_med_listings_price_cut_perc_uc_sfrcondo_sm_week.csv\n", "processing Metro_perc_listings_price_cut_uc_sfr_month.csv\n", "processing Metro_med_doz_pending_uc_sfrcondo_week.csv\n", "processing Metro_mean_listings_price_cut_perc_uc_sfrcondo_sm_month.csv\n", "processing Metro_perc_listings_price_cut_uc_sfr_sm_month.csv\n", "processing Metro_median_days_to_close_uc_sfrcondo_month.csv\n", "processing Metro_perc_listings_price_cut_uc_sfr_sm_week.csv\n", "processing Metro_mean_listings_price_cut_perc_uc_sfrcondo_month.csv\n", "processing Metro_mean_listings_price_cut_amt_uc_sfr_month.csv\n", "processing Metro_mean_doz_pending_uc_sfrcondo_month.csv\n" ] } ], "source": [ "data_frames = []\n", "\n", "exclude_columns = [\n", " \"RegionID\",\n", " \"SizeRank\",\n", " \"RegionName\",\n", " \"RegionType\",\n", " \"StateName\",\n", " \"Home Type\",\n", "]\n", "\n", "slug_column_mappings = {\n", " \"_mean_listings_price_cut_amt_\": \"Mean Listings Price Cut Amount\",\n", " \"_med_doz_pending_\": \"Median Days on Pending\",\n", " \"_median_days_to_pending_\": \"Median Days to Close\",\n", " \"_perc_listings_price_cut_\": \"Percent Listings Price Cut\",\n", "}\n", "\n", "\n", "for filename in os.listdir(FULL_DATA_DIR_PATH):\n", " if filename.endswith(\".csv\"):\n", " print(\"processing \" + filename)\n", " # skip month files for now since they are redundant\n", " if \"month\" in filename:\n", " continue\n", "\n", " cur_df = pd.read_csv(os.path.join(FULL_DATA_DIR_PATH, filename))\n", "\n", " cur_df[\"RegionName\"] = cur_df[\"RegionName\"].astype(str)\n", " cur_df = set_home_type(cur_df, filename)\n", "\n", " data_frames = handle_slug_column_mappings(\n", " data_frames, slug_column_mappings, exclude_columns, filename, cur_df\n", " )\n", "\n", "\n", "combined_df = get_combined_df(\n", " data_frames,\n", " [\n", " \"RegionID\",\n", " \"SizeRank\",\n", " \"RegionName\",\n", " \"RegionType\",\n", " \"StateName\",\n", " \"Home Type\",\n", " \"Date\",\n", " ],\n", ")\n", "\n", "combined_df" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Region ID | \n", "Size Rank | \n", "Region | \n", "Region Type | \n", "State | \n", "Home Type | \n", "Date | \n", "Percent Listings Price Cut | \n", "Mean Listings Price Cut Amount | \n", "Percent Listings Price Cut (Smoothed) | \n", "Mean Listings Price Cut Amount (Smoothed) | \n", "Median Days on Pending (Smoothed) | \n", "Median Days on Pending | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "102001 | \n", "0 | \n", "United States | \n", "country | \n", "NaN | \n", "SFR | \n", "2018-01-06 | \n", "NaN | \n", "13508.368375 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
1 | \n", "102001 | \n", "0 | \n", "United States | \n", "country | \n", "NaN | \n", "SFR | \n", "2018-01-13 | \n", "0.049042 | \n", "14114.788383 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
2 | \n", "102001 | \n", "0 | \n", "United States | \n", "country | \n", "NaN | \n", "SFR | \n", "2018-01-20 | \n", "0.044740 | \n", "14326.128956 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
3 | \n", "102001 | \n", "0 | \n", "United States | \n", "country | \n", "NaN | \n", "SFR | \n", "2018-01-27 | \n", "0.047930 | \n", "13998.585612 | \n", "NaN | \n", "13998.585612 | \n", "NaN | \n", "NaN | \n", "
4 | \n", "102001 | \n", "0 | \n", "United States | \n", "country | \n", "NaN | \n", "SFR | \n", "2018-02-03 | \n", "0.047622 | \n", "14120.035549 | \n", "0.047622 | \n", "14120.035549 | \n", "NaN | \n", "NaN | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
586709 | \n", "845172 | \n", "769 | \n", "Winfield, KS | \n", "msa | \n", "KS | \n", "all homes | \n", "2024-01-06 | \n", "0.094017 | \n", "NaN | \n", "0.037378 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
586710 | \n", "845172 | \n", "769 | \n", "Winfield, KS | \n", "msa | \n", "KS | \n", "all homes | \n", "2024-01-13 | \n", "0.070175 | \n", "NaN | \n", "0.043203 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
586711 | \n", "845172 | \n", "769 | \n", "Winfield, KS | \n", "msa | \n", "KS | \n", "all homes | \n", "2024-01-20 | \n", "0.043478 | \n", "NaN | \n", "0.054073 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
586712 | \n", "845172 | \n", "769 | \n", "Winfield, KS | \n", "msa | \n", "KS | \n", "all homes | \n", "2024-01-27 | \n", "0.036697 | \n", "NaN | \n", "0.061092 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
586713 | \n", "845172 | \n", "769 | \n", "Winfield, KS | \n", "msa | \n", "KS | \n", "all homes | \n", "2024-02-03 | \n", "0.077670 | \n", "NaN | \n", "0.057005 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
586714 rows × 13 columns
\n", "