{ "cells": [ { "cell_type": "code", "execution_count": 1, "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", ")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "DATA_DIR = \"../data\"\n", "PROCESSED_DIR = \"../processed/\"\n", "FACET_DIR = \"home_values/\"\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 City_zhvi_uc_condo_tier_0.33_0.67_sm_sa_month.csv\n", "processing City_zhvi_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Metro_zhvi_uc_sfrcondo_tier_0.67_1.0_sm_sa_month.csv\n", "processing County_zhvi_uc_sfrcondo_tier_0.67_1.0_sm_sa_month.csv\n", "processing Metro_zhvi_bdrmcnt_2_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing County_zhvi_bdrmcnt_4_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing County_zhvi_uc_sfr_tier_0.33_0.67_sm_sa_month.csv\n", "processing Neighborhood_zhvi_bdrmcnt_4_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing State_zhvi_uc_sfr_tier_0.33_0.67_sm_sa_month.csv\n", "processing County_zhvi_uc_condo_tier_0.33_0.67_sm_sa_month.csv\n", "processing City_zhvi_bdrmcnt_4_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing State_zhvi_bdrmcnt_5_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Zip_zhvi_bdrmcnt_2_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing City_zhvi_uc_sfrcondo_tier_0.67_1.0_sm_sa_month.csv\n", "processing Zip_zhvi_uc_condo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Neighborhood_zhvi_uc_sfr_sm_sa_month.csv\n", "processing Metro_zhvi_uc_sfr_tier_0.33_0.67_sm_sa_month.csv\n", "processing State_zhvi_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Zip_zhvi_bdrmcnt_1_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing County_zhvi_bdrmcnt_5_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Metro_zhvi_uc_condo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Metro_zhvi_bdrmcnt_3_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Neighborhood_zhvi_bdrmcnt_5_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Zip_zhvi_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing State_zhvi_uc_sfrcondo_tier_0.0_0.33_sm_sa_month.csv\n", "processing Metro_zhvi_bdrmcnt_1_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Zip_zhvi_uc_sfr_tier_0.33_0.67_sm_sa_month.csv\n", "processing City_zhvi_bdrmcnt_5_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing State_zhvi_bdrmcnt_4_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing State_zhvi_uc_condo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Zip_zhvi_bdrmcnt_3_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Neighborhood_zhvi_bdrmcnt_1_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing City_zhvi_bdrmcnt_3_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing County_zhvi_bdrmcnt_1_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Neighborhood_zhvi_uc_condo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Metro_zhvi_uc_sfrcondo_tier_0.33_0.67_month.csv\n", "processing Zip_zhvi_bdrmcnt_5_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing County_zhvi_uc_sfrcondo_tier_0.0_0.33_sm_sa_month.csv\n", "processing State_zhvi_bdrmcnt_2_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Metro_zhvi_uc_sfrcondo_tier_0.0_0.33_sm_sa_month.csv\n", "processing City_zhvi_uc_sfr_tier_0.33_0.67_sm_sa_month.csv\n", "processing City_zhvi_bdrmcnt_1_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Neighborhood_zhvi_bdrmcnt_3_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Metro_zhvi_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Metro_zhvi_bdrmcnt_5_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing County_zhvi_bdrmcnt_3_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing City_zhvi_bdrmcnt_2_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Neighborhood_zhvi_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing State_zhvi_uc_sfrcondo_tier_0.67_1.0_sm_sa_month.csv\n", "processing Zip_zhvi_bdrmcnt_4_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing State_zhvi_bdrmcnt_3_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing State_zhvi_bdrmcnt_1_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Neighborhood_zhvi_bdrmcnt_2_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing County_zhvi_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing County_zhvi_bdrmcnt_2_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n", "processing Metro_zhvi_bdrmcnt_4_uc_sfrcondo_tier_0.33_0.67_sm_sa_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", "
RegionIDSizeRankRegionNameRegionTypeStateNameBedroom CountHome TypeDateMid Tier ZHVI (Smoothed) (Seasonally Adjusted)Bottom Tier ZHVI (Smoothed) (Seasonally Adjusted)Top Tier ZHVI (Smoothed) (Seasonally Adjusted)
0348Alaskastatenan1-Bedroomall homes (SFR/condo)2000-01-3181310.639504NaNNaN
1348Alaskastatenan1-Bedroomall homes (SFR/condo)2000-02-2980419.761984NaNNaN
2348Alaskastatenan1-Bedroomall homes (SFR/condo)2000-03-3180480.449461NaNNaN
3348Alaskastatenan1-Bedroomall homes (SFR/condo)2000-04-3079799.206525NaNNaN
4348Alaskastatenan1-Bedroomall homes (SFR/condo)2000-05-3179666.469861NaNNaN
....................................
1179076251WyomingstatenanAll Bedroomscondo2023-09-30486974.735908NaNNaN
1179086251WyomingstatenanAll Bedroomscondo2023-10-31485847.539614NaNNaN
1179096251WyomingstatenanAll Bedroomscondo2023-11-30484223.885775NaNNaN
1179106251WyomingstatenanAll Bedroomscondo2023-12-31481522.403338NaNNaN
1179116251WyomingstatenanAll Bedroomscondo2024-01-31481181.718200NaNNaN
\n", "

117912 rows × 11 columns

\n", "
" ], "text/plain": [ " RegionID SizeRank RegionName RegionType StateName Bedroom Count \\\n", "0 3 48 Alaska state nan 1-Bedroom \n", "1 3 48 Alaska state nan 1-Bedroom \n", "2 3 48 Alaska state nan 1-Bedroom \n", "3 3 48 Alaska state nan 1-Bedroom \n", "4 3 48 Alaska state nan 1-Bedroom \n", "... ... ... ... ... ... ... \n", "117907 62 51 Wyoming state nan All Bedrooms \n", "117908 62 51 Wyoming state nan All Bedrooms \n", "117909 62 51 Wyoming state nan All Bedrooms \n", "117910 62 51 Wyoming state nan All Bedrooms \n", "117911 62 51 Wyoming state nan All Bedrooms \n", "\n", " Home Type Date \\\n", "0 all homes (SFR/condo) 2000-01-31 \n", "1 all homes (SFR/condo) 2000-02-29 \n", "2 all homes (SFR/condo) 2000-03-31 \n", "3 all homes (SFR/condo) 2000-04-30 \n", "4 all homes (SFR/condo) 2000-05-31 \n", "... ... ... \n", "117907 condo 2023-09-30 \n", "117908 condo 2023-10-31 \n", "117909 condo 2023-11-30 \n", "117910 condo 2023-12-31 \n", "117911 condo 2024-01-31 \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n", "0 81310.639504 \n", "1 80419.761984 \n", "2 80480.449461 \n", "3 79799.206525 \n", "4 79666.469861 \n", "... ... \n", "117907 486974.735908 \n", "117908 485847.539614 \n", "117909 484223.885775 \n", "117910 481522.403338 \n", "117911 481181.718200 \n", "\n", " Bottom Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Top Tier ZHVI (Smoothed) (Seasonally Adjusted) \n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", "[117912 rows x 11 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data_frames = []\n", "\n", "slug_column_mappings = {\n", " \"_tier_0.0_0.33_\": \"Bottom Tier ZHVI\",\n", " \"_tier_0.33_0.67_\": \"Mid Tier ZHVI\",\n", " \"_tier_0.67_1.0_\": \"Top Tier ZHVI\",\n", " \"\": \"ZHVI\",\n", "}\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", " \"Bedroom Count\",\n", " \"Home Type\",\n", " ]\n", "\n", " if \"Zip\" in filename:\n", " continue\n", " if \"Neighborhood\" in filename:\n", " continue\n", " if \"City\" in filename:\n", " continue\n", " if \"Metro\" in filename:\n", " continue\n", " if \"County\" in filename:\n", " continue\n", "\n", " if \"City\" in filename:\n", " exclude_columns = exclude_columns + [\"State\", \"Metro\", \"CountyName\"]\n", " elif \"Zip\" in filename:\n", " exclude_columns = exclude_columns + [\n", " \"State\",\n", " \"City\",\n", " \"Metro\",\n", " \"CountyName\",\n", " ]\n", " elif \"County\" in filename:\n", " exclude_columns = exclude_columns + [\n", " \"State\",\n", " \"Metro\",\n", " \"StateCodeFIPS\",\n", " \"MunicipalCodeFIPS\",\n", " ]\n", " elif \"Neighborhood\" in filename:\n", " exclude_columns = exclude_columns + [\n", " \"State\",\n", " \"City\",\n", " \"Metro\",\n", " \"CountyName\",\n", " ]\n", "\n", " if \"_bdrmcnt_1_\" in filename:\n", " cur_df[\"Bedroom Count\"] = \"1-Bedroom\"\n", " elif \"_bdrmcnt_2_\" in filename:\n", " cur_df[\"Bedroom Count\"] = \"2-Bedrooms\"\n", " elif \"_bdrmcnt_3_\" in filename:\n", " cur_df[\"Bedroom Count\"] = \"3-Bedrooms\"\n", " elif \"_bdrmcnt_4_\" in filename:\n", " cur_df[\"Bedroom Count\"] = \"4-Bedrooms\"\n", " elif \"_bdrmcnt_5_\" in filename:\n", " cur_df[\"Bedroom Count\"] = \"5+-Bedrooms\"\n", " else:\n", " cur_df[\"Bedroom Count\"] = \"All Bedrooms\"\n", "\n", " if \"_uc_sfr_\" in filename:\n", " cur_df[\"Home Type\"] = \"SFR\"\n", " elif \"_uc_sfrcondo_\" in filename:\n", " cur_df[\"Home Type\"] = \"all homes (SFR/condo)\"\n", " elif \"_uc_condo_\" in filename:\n", " cur_df[\"Home Type\"] = \"condo\"\n", "\n", " cur_df[\"StateName\"] = cur_df[\"StateName\"].astype(str)\n", " cur_df[\"RegionName\"] = cur_df[\"RegionName\"].astype(str)\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", " \"Bedroom Count\",\n", " \"Home Type\",\n", " \"Date\",\n", " ],\n", ")\n", "\n", "combined_df" ] }, { "cell_type": "code", "execution_count": 11, "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", "
RegionIDSizeRankRegionNameRegionTypeStateNameBedroom CountHome TypeDateMid Tier ZHVI (Smoothed) (Seasonally Adjusted)Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_1Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_2Bottom Tier ZHVI (Smoothed) (Seasonally Adjusted)Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_4Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_5Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_6Top Tier ZHVI (Smoothed) (Seasonally Adjusted)Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_8Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_9
0348AlaskastateAlaska1-Bedroomsall homes (SFR/condo)2000-01-31NaNNaNNaNNaNNaNNaNNaNNaNNaN81310.639504
1348AlaskastateAlaska1-Bedroomsall homes (SFR/condo)2000-02-29NaNNaNNaNNaNNaNNaNNaNNaNNaN80419.761984
2348AlaskastateAlaska1-Bedroomsall homes (SFR/condo)2000-03-31NaNNaNNaNNaNNaNNaNNaNNaNNaN80480.449461
3348AlaskastateAlaska1-Bedroomsall homes (SFR/condo)2000-04-30NaNNaNNaNNaNNaNNaNNaNNaNNaN79799.206525
4348AlaskastateAlaska1-Bedroomsall homes (SFR/condo)2000-05-31NaNNaNNaNNaNNaNNaNNaNNaNNaN79666.469861
.........................................................
1179076251WyomingstateWyomingAll Bedroomscondo2023-09-30NaNNaNNaNNaNNaN486974.735908NaNNaNNaNNaN
1179086251WyomingstateWyomingAll Bedroomscondo2023-10-31NaNNaNNaNNaNNaN485847.539614NaNNaNNaNNaN
1179096251WyomingstateWyomingAll Bedroomscondo2023-11-30NaNNaNNaNNaNNaN484223.885775NaNNaNNaNNaN
1179106251WyomingstateWyomingAll Bedroomscondo2023-12-31NaNNaNNaNNaNNaN481522.403338NaNNaNNaNNaN
1179116251WyomingstateWyomingAll Bedroomscondo2024-01-31NaNNaNNaNNaNNaN481181.718200NaNNaNNaNNaN
\n", "

117912 rows × 18 columns

\n", "
" ], "text/plain": [ " RegionID SizeRank RegionName RegionType StateName Bedroom Count \\\n", "0 3 48 Alaska state Alaska 1-Bedrooms \n", "1 3 48 Alaska state Alaska 1-Bedrooms \n", "2 3 48 Alaska state Alaska 1-Bedrooms \n", "3 3 48 Alaska state Alaska 1-Bedrooms \n", "4 3 48 Alaska state Alaska 1-Bedrooms \n", "... ... ... ... ... ... ... \n", "117907 62 51 Wyoming state Wyoming All Bedrooms \n", "117908 62 51 Wyoming state Wyoming All Bedrooms \n", "117909 62 51 Wyoming state Wyoming All Bedrooms \n", "117910 62 51 Wyoming state Wyoming All Bedrooms \n", "117911 62 51 Wyoming state Wyoming All Bedrooms \n", "\n", " Home Type Date \\\n", "0 all homes (SFR/condo) 2000-01-31 \n", "1 all homes (SFR/condo) 2000-02-29 \n", "2 all homes (SFR/condo) 2000-03-31 \n", "3 all homes (SFR/condo) 2000-04-30 \n", "4 all homes (SFR/condo) 2000-05-31 \n", "... ... ... \n", "117907 condo 2023-09-30 \n", "117908 condo 2023-10-31 \n", "117909 condo 2023-11-30 \n", "117910 condo 2023-12-31 \n", "117911 condo 2024-01-31 \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_1 \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_2 \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Bottom Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_4 \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_5 \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 486974.735908 \n", "117908 485847.539614 \n", "117909 484223.885775 \n", "117910 481522.403338 \n", "117911 481181.718200 \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_6 \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Top Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_8 \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_9 \n", "0 81310.639504 \n", "1 80419.761984 \n", "2 80480.449461 \n", "3 79799.206525 \n", "4 79666.469861 \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", "[117912 rows x 18 columns]" ] }, "execution_count": 11, "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", " if row[\"RegionType\"] == \"state\":\n", " final_df.at[index, \"StateName\"] = row[\"RegionName\"]\n", "\n", "# coalesce State and StateName columns\n", "# final_df[\"State\"] = final_df[\"State\"].combine_first(final_df[\"StateName\"])\n", "# final_df[\"County\"] = final_df[\"County\"].combine_first(final_df[\"CountyName\"])\n", "\n", "# final_df = final_df.drop(\n", "# columns=[\n", "# \"StateName\",\n", "# # \"CountyName\"\n", "# ]\n", "# )\n", "final_df" ] }, { "cell_type": "code", "execution_count": 12, "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", "
Region IDSize RankRegionRegion TypeStateBedroom CountHome TypeDateMid Tier ZHVI (Smoothed) (Seasonally Adjusted)Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_1Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_2Bottom Tier ZHVI (Smoothed) (Seasonally Adjusted)Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_4Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_5Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_6Top Tier ZHVI (Smoothed) (Seasonally Adjusted)Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_8Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_9
0348AlaskastateAlaska1-Bedroomsall homes (SFR/condo)2000-01-31NaNNaNNaNNaNNaNNaNNaNNaNNaN81310.639504
1348AlaskastateAlaska1-Bedroomsall homes (SFR/condo)2000-02-29NaNNaNNaNNaNNaNNaNNaNNaNNaN80419.761984
2348AlaskastateAlaska1-Bedroomsall homes (SFR/condo)2000-03-31NaNNaNNaNNaNNaNNaNNaNNaNNaN80480.449461
3348AlaskastateAlaska1-Bedroomsall homes (SFR/condo)2000-04-30NaNNaNNaNNaNNaNNaNNaNNaNNaN79799.206525
4348AlaskastateAlaska1-Bedroomsall homes (SFR/condo)2000-05-31NaNNaNNaNNaNNaNNaNNaNNaNNaN79666.469861
.........................................................
1179076251WyomingstateWyomingAll Bedroomscondo2023-09-30NaNNaNNaNNaNNaN486974.735908NaNNaNNaNNaN
1179086251WyomingstateWyomingAll Bedroomscondo2023-10-31NaNNaNNaNNaNNaN485847.539614NaNNaNNaNNaN
1179096251WyomingstateWyomingAll Bedroomscondo2023-11-30NaNNaNNaNNaNNaN484223.885775NaNNaNNaNNaN
1179106251WyomingstateWyomingAll Bedroomscondo2023-12-31NaNNaNNaNNaNNaN481522.403338NaNNaNNaNNaN
1179116251WyomingstateWyomingAll Bedroomscondo2024-01-31NaNNaNNaNNaNNaN481181.718200NaNNaNNaNNaN
\n", "

117912 rows × 18 columns

\n", "
" ], "text/plain": [ " Region ID Size Rank Region Region Type State Bedroom Count \\\n", "0 3 48 Alaska state Alaska 1-Bedrooms \n", "1 3 48 Alaska state Alaska 1-Bedrooms \n", "2 3 48 Alaska state Alaska 1-Bedrooms \n", "3 3 48 Alaska state Alaska 1-Bedrooms \n", "4 3 48 Alaska state Alaska 1-Bedrooms \n", "... ... ... ... ... ... ... \n", "117907 62 51 Wyoming state Wyoming All Bedrooms \n", "117908 62 51 Wyoming state Wyoming All Bedrooms \n", "117909 62 51 Wyoming state Wyoming All Bedrooms \n", "117910 62 51 Wyoming state Wyoming All Bedrooms \n", "117911 62 51 Wyoming state Wyoming All Bedrooms \n", "\n", " Home Type Date \\\n", "0 all homes (SFR/condo) 2000-01-31 \n", "1 all homes (SFR/condo) 2000-02-29 \n", "2 all homes (SFR/condo) 2000-03-31 \n", "3 all homes (SFR/condo) 2000-04-30 \n", "4 all homes (SFR/condo) 2000-05-31 \n", "... ... ... \n", "117907 condo 2023-09-30 \n", "117908 condo 2023-10-31 \n", "117909 condo 2023-11-30 \n", "117910 condo 2023-12-31 \n", "117911 condo 2024-01-31 \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_1 \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_2 \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Bottom Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_4 \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_5 \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 486974.735908 \n", "117908 485847.539614 \n", "117909 484223.885775 \n", "117910 481522.403338 \n", "117911 481181.718200 \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_6 \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Top Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_8 \\\n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", " Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_9 \n", "0 81310.639504 \n", "1 80419.761984 \n", "2 80480.449461 \n", "3 79799.206525 \n", "4 79666.469861 \n", "... ... \n", "117907 NaN \n", "117908 NaN \n", "117909 NaN \n", "117910 NaN \n", "117911 NaN \n", "\n", "[117912 rows x 18 columns]" ] }, "execution_count": 12, "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", " \"StateName\": \"State\",\n", " \"MunicipalCodeFIPS\": \"Municipal Code FIPS\",\n", " }\n", ")\n", "\n", "final_df" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "save_final_df_as_jsonl(FULL_PROCESSED_DIR_PATH, final_df)" ] } ], "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 }