fix: simplify processors more
Browse files- processed/days_on_market/final.jsonl +2 -2
- processed/home_values_forecasts/final.jsonl +2 -2
- processors/days_on_market.ipynb +41 -110
- processors/for_sale_listings.ipynb +10 -30
- processors/helpers.py +27 -2
- processors/home_value_forecasts.ipynb +455 -456
- processors/home_values.ipynb +67 -644
- processors/new_construction.ipynb +16 -38
- processors/rentals.ipynb +99 -81
- processors/sales.ipynb +13 -39
processed/days_on_market/final.jsonl
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:52768ecdeb897b82c7fb783c3dde12d04b0fa68eea0adf6f60ad60a630d3cb85
|
3 |
+
size 232657387
|
processed/home_values_forecasts/final.jsonl
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ae38d8b222b98347a9841ea8ca153cbb834af36a9dae7df6ad3326e64ad3723a
|
3 |
+
size 13922709
|
processors/days_on_market.ipynb
CHANGED
@@ -2,19 +2,24 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
-
"from helpers import
|
|
|
|
|
|
|
|
|
|
|
13 |
]
|
14 |
},
|
15 |
{
|
16 |
"cell_type": "code",
|
17 |
-
"execution_count":
|
18 |
"metadata": {},
|
19 |
"outputs": [],
|
20 |
"source": [
|
@@ -27,16 +32,9 @@
|
|
27 |
},
|
28 |
{
|
29 |
"cell_type": "code",
|
30 |
-
"execution_count":
|
31 |
"metadata": {},
|
32 |
"outputs": [
|
33 |
-
{
|
34 |
-
"name": "stdout",
|
35 |
-
"output_type": "stream",
|
36 |
-
"text": [
|
37 |
-
"dict_values(['Mean Listings Price Cut Amount', 'Median Days on Pending', 'Median Days to Close', 'Percent Listings Price Cut'])\n"
|
38 |
-
]
|
39 |
-
},
|
40 |
{
|
41 |
"data": {
|
42 |
"text/html": [
|
@@ -131,7 +129,7 @@
|
|
131 |
" <td>NaN</td>\n",
|
132 |
" <td>SFR</td>\n",
|
133 |
" <td>2018-01-27</td>\n",
|
134 |
-
" <td>
|
135 |
" <td>0.047930</td>\n",
|
136 |
" <td>13998.585612</td>\n",
|
137 |
" <td>NaN</td>\n",
|
@@ -147,10 +145,10 @@
|
|
147 |
" <td>NaN</td>\n",
|
148 |
" <td>SFR</td>\n",
|
149 |
" <td>2018-02-03</td>\n",
|
150 |
-
" <td>
|
151 |
" <td>0.047622</td>\n",
|
152 |
" <td>14120.035549</td>\n",
|
153 |
-
" <td>
|
154 |
" <td>NaN</td>\n",
|
155 |
" <td>NaN</td>\n",
|
156 |
" </tr>\n",
|
@@ -256,75 +254,23 @@
|
|
256 |
"</div>"
|
257 |
],
|
258 |
"text/plain": [
|
259 |
-
" RegionID
|
260 |
-
"0 102001
|
261 |
-
"1 102001
|
262 |
-
"2 102001
|
263 |
-
"3 102001
|
264 |
-
"4 102001
|
265 |
-
"... ...
|
266 |
-
"586709 845172
|
267 |
-
"586710 845172
|
268 |
-
"586711 845172
|
269 |
-
"586712 845172
|
270 |
-
"586713 845172
|
271 |
-
"\n",
|
272 |
-
" Home Type Date \\\n",
|
273 |
-
"0 SFR 2018-01-06 \n",
|
274 |
-
"1 SFR 2018-01-13 \n",
|
275 |
-
"2 SFR 2018-01-20 \n",
|
276 |
-
"3 SFR 2018-01-27 \n",
|
277 |
-
"4 SFR 2018-02-03 \n",
|
278 |
-
"... ... ... \n",
|
279 |
-
"586709 all homes (SFR + Condo) 2024-01-06 \n",
|
280 |
-
"586710 all homes (SFR + Condo) 2024-01-13 \n",
|
281 |
-
"586711 all homes (SFR + Condo) 2024-01-20 \n",
|
282 |
-
"586712 all homes (SFR + Condo) 2024-01-27 \n",
|
283 |
-
"586713 all homes (SFR + Condo) 2024-02-03 \n",
|
284 |
-
"\n",
|
285 |
-
" Mean Listings Price Cut Amount (Smoothed) Percent Listings Price Cut \\\n",
|
286 |
-
"0 NaN NaN \n",
|
287 |
-
"1 NaN 0.049042 \n",
|
288 |
-
"2 NaN 0.044740 \n",
|
289 |
-
"3 NaN 0.047930 \n",
|
290 |
-
"4 NaN 0.047622 \n",
|
291 |
-
"... ... ... \n",
|
292 |
-
"586709 NaN 0.094017 \n",
|
293 |
-
"586710 NaN 0.070175 \n",
|
294 |
-
"586711 NaN 0.043478 \n",
|
295 |
-
"586712 NaN 0.036697 \n",
|
296 |
-
"586713 NaN 0.077670 \n",
|
297 |
-
"\n",
|
298 |
-
" Mean Listings Price Cut Amount Percent Listings Price Cut (Smoothed) \\\n",
|
299 |
-
"0 13508.368375 NaN \n",
|
300 |
-
"1 14114.788383 NaN \n",
|
301 |
-
"2 14326.128956 NaN \n",
|
302 |
-
"3 13998.585612 NaN \n",
|
303 |
-
"4 14120.035549 NaN \n",
|
304 |
-
"... ... ... \n",
|
305 |
-
"586709 NaN 0.037378 \n",
|
306 |
-
"586710 NaN 0.043203 \n",
|
307 |
-
"586711 NaN 0.054073 \n",
|
308 |
-
"586712 NaN 0.061092 \n",
|
309 |
-
"586713 NaN 0.057005 \n",
|
310 |
-
"\n",
|
311 |
-
" Median Days on Pending (Smoothed) Median Days on Pending \n",
|
312 |
-
"0 NaN NaN \n",
|
313 |
-
"1 NaN NaN \n",
|
314 |
-
"2 NaN NaN \n",
|
315 |
-
"3 NaN NaN \n",
|
316 |
-
"4 NaN NaN \n",
|
317 |
-
"... ... ... \n",
|
318 |
-
"586709 NaN NaN \n",
|
319 |
-
"586710 NaN NaN \n",
|
320 |
-
"586711 NaN NaN \n",
|
321 |
-
"586712 NaN NaN \n",
|
322 |
-
"586713 NaN NaN \n",
|
323 |
"\n",
|
324 |
"[586714 rows x 13 columns]"
|
325 |
]
|
326 |
},
|
327 |
-
"execution_count":
|
328 |
"metadata": {},
|
329 |
"output_type": "execute_result"
|
330 |
}
|
@@ -351,13 +297,13 @@
|
|
351 |
"\n",
|
352 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
353 |
" if filename.endswith(\".csv\"):\n",
|
354 |
-
"
|
355 |
-
" cur_df = pd.read_csv(os.path.join(FULL_DATA_DIR_PATH, filename))\n",
|
356 |
-
"\n",
|
357 |
" # skip month files for now since they are redundant\n",
|
358 |
" if \"month\" in filename:\n",
|
359 |
" continue\n",
|
360 |
"\n",
|
|
|
|
|
361 |
" if \"_uc_sfrcondo_\" in filename:\n",
|
362 |
" cur_df[\"Home Type\"] = \"all homes (SFR + Condo)\"\n",
|
363 |
" # change column type to string\n",
|
@@ -365,22 +311,9 @@
|
|
365 |
" elif \"_uc_sfr_\" in filename:\n",
|
366 |
" cur_df[\"Home Type\"] = \"SFR\"\n",
|
367 |
"\n",
|
368 |
-
"
|
369 |
-
"
|
370 |
-
"\n",
|
371 |
-
" # iterate over slug column mappings and get df\n",
|
372 |
-
" for slug, col_name in slug_column_mappings.items():\n",
|
373 |
-
" if slug in filename:\n",
|
374 |
-
" cur_df = get_df(\n",
|
375 |
-
" cur_df,\n",
|
376 |
-
" exclude_columns,\n",
|
377 |
-
" columns_to_pivot,\n",
|
378 |
-
" col_name,\n",
|
379 |
-
" filename,\n",
|
380 |
-
" )\n",
|
381 |
-
"\n",
|
382 |
-
" data_frames.append(cur_df)\n",
|
383 |
-
" break\n",
|
384 |
"\n",
|
385 |
"\n",
|
386 |
"combined_df = get_combined_df(\n",
|
@@ -396,16 +329,14 @@
|
|
396 |
" ],\n",
|
397 |
")\n",
|
398 |
"\n",
|
399 |
-
"
|
400 |
-
"\n",
|
401 |
-
"combined_df = coalesce_columns(combined_df, columns_to_coalesce)\n",
|
402 |
"\n",
|
403 |
"combined_df"
|
404 |
]
|
405 |
},
|
406 |
{
|
407 |
"cell_type": "code",
|
408 |
-
"execution_count":
|
409 |
"metadata": {},
|
410 |
"outputs": [
|
411 |
{
|
@@ -502,7 +433,7 @@
|
|
502 |
" <td>NaN</td>\n",
|
503 |
" <td>SFR</td>\n",
|
504 |
" <td>2018-01-27</td>\n",
|
505 |
-
" <td>
|
506 |
" <td>0.047930</td>\n",
|
507 |
" <td>13998.585612</td>\n",
|
508 |
" <td>NaN</td>\n",
|
@@ -518,10 +449,10 @@
|
|
518 |
" <td>NaN</td>\n",
|
519 |
" <td>SFR</td>\n",
|
520 |
" <td>2018-02-03</td>\n",
|
521 |
-
" <td>
|
522 |
" <td>0.047622</td>\n",
|
523 |
" <td>14120.035549</td>\n",
|
524 |
-
" <td>
|
525 |
" <td>NaN</td>\n",
|
526 |
" <td>NaN</td>\n",
|
527 |
" </tr>\n",
|
@@ -657,8 +588,8 @@
|
|
657 |
"0 NaN NaN \n",
|
658 |
"1 NaN 0.049042 \n",
|
659 |
"2 NaN 0.044740 \n",
|
660 |
-
"3
|
661 |
-
"4
|
662 |
"... ... ... \n",
|
663 |
"586709 NaN 0.094017 \n",
|
664 |
"586710 NaN 0.070175 \n",
|
@@ -671,7 +602,7 @@
|
|
671 |
"1 14114.788383 NaN \n",
|
672 |
"2 14326.128956 NaN \n",
|
673 |
"3 13998.585612 NaN \n",
|
674 |
-
"4 14120.035549
|
675 |
"... ... ... \n",
|
676 |
"586709 NaN 0.037378 \n",
|
677 |
"586710 NaN 0.043203 \n",
|
@@ -695,7 +626,7 @@
|
|
695 |
"[586714 rows x 13 columns]"
|
696 |
]
|
697 |
},
|
698 |
-
"execution_count":
|
699 |
"metadata": {},
|
700 |
"output_type": "execute_result"
|
701 |
}
|
@@ -717,7 +648,7 @@
|
|
717 |
},
|
718 |
{
|
719 |
"cell_type": "code",
|
720 |
-
"execution_count":
|
721 |
"metadata": {},
|
722 |
"outputs": [],
|
723 |
"source": [
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
+
"from helpers import (\n",
|
13 |
+
" get_combined_df,\n",
|
14 |
+
" coalesce_columns,\n",
|
15 |
+
" save_final_df_as_jsonl,\n",
|
16 |
+
" handle_slug_column_mappings,\n",
|
17 |
+
")"
|
18 |
]
|
19 |
},
|
20 |
{
|
21 |
"cell_type": "code",
|
22 |
+
"execution_count": 2,
|
23 |
"metadata": {},
|
24 |
"outputs": [],
|
25 |
"source": [
|
|
|
32 |
},
|
33 |
{
|
34 |
"cell_type": "code",
|
35 |
+
"execution_count": 3,
|
36 |
"metadata": {},
|
37 |
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
{
|
39 |
"data": {
|
40 |
"text/html": [
|
|
|
129 |
" <td>NaN</td>\n",
|
130 |
" <td>SFR</td>\n",
|
131 |
" <td>2018-01-27</td>\n",
|
132 |
+
" <td>13998.585612</td>\n",
|
133 |
" <td>0.047930</td>\n",
|
134 |
" <td>13998.585612</td>\n",
|
135 |
" <td>NaN</td>\n",
|
|
|
145 |
" <td>NaN</td>\n",
|
146 |
" <td>SFR</td>\n",
|
147 |
" <td>2018-02-03</td>\n",
|
148 |
+
" <td>14120.035549</td>\n",
|
149 |
" <td>0.047622</td>\n",
|
150 |
" <td>14120.035549</td>\n",
|
151 |
+
" <td>0.047622</td>\n",
|
152 |
" <td>NaN</td>\n",
|
153 |
" <td>NaN</td>\n",
|
154 |
" </tr>\n",
|
|
|
254 |
"</div>"
|
255 |
],
|
256 |
"text/plain": [
|
257 |
+
" RegionID ... Median Days on Pending\n",
|
258 |
+
"0 102001 ... NaN\n",
|
259 |
+
"1 102001 ... NaN\n",
|
260 |
+
"2 102001 ... NaN\n",
|
261 |
+
"3 102001 ... NaN\n",
|
262 |
+
"4 102001 ... NaN\n",
|
263 |
+
"... ... ... ...\n",
|
264 |
+
"586709 845172 ... NaN\n",
|
265 |
+
"586710 845172 ... NaN\n",
|
266 |
+
"586711 845172 ... NaN\n",
|
267 |
+
"586712 845172 ... NaN\n",
|
268 |
+
"586713 845172 ... NaN\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
"\n",
|
270 |
"[586714 rows x 13 columns]"
|
271 |
]
|
272 |
},
|
273 |
+
"execution_count": 3,
|
274 |
"metadata": {},
|
275 |
"output_type": "execute_result"
|
276 |
}
|
|
|
297 |
"\n",
|
298 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
299 |
" if filename.endswith(\".csv\"):\n",
|
300 |
+
" print(\"processing \" + filename)\n",
|
|
|
|
|
301 |
" # skip month files for now since they are redundant\n",
|
302 |
" if \"month\" in filename:\n",
|
303 |
" continue\n",
|
304 |
"\n",
|
305 |
+
" cur_df = pd.read_csv(os.path.join(FULL_DATA_DIR_PATH, filename))\n",
|
306 |
+
"\n",
|
307 |
" if \"_uc_sfrcondo_\" in filename:\n",
|
308 |
" cur_df[\"Home Type\"] = \"all homes (SFR + Condo)\"\n",
|
309 |
" # change column type to string\n",
|
|
|
311 |
" elif \"_uc_sfr_\" in filename:\n",
|
312 |
" cur_df[\"Home Type\"] = \"SFR\"\n",
|
313 |
"\n",
|
314 |
+
" data_frames = handle_slug_column_mappings(\n",
|
315 |
+
" data_frames, slug_column_mappings, exclude_columns, filename, cur_df\n",
|
316 |
+
" )\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
"\n",
|
318 |
"\n",
|
319 |
"combined_df = get_combined_df(\n",
|
|
|
329 |
" ],\n",
|
330 |
")\n",
|
331 |
"\n",
|
332 |
+
"combined_df = coalesce_columns(combined_df)\n",
|
|
|
|
|
333 |
"\n",
|
334 |
"combined_df"
|
335 |
]
|
336 |
},
|
337 |
{
|
338 |
"cell_type": "code",
|
339 |
+
"execution_count": 9,
|
340 |
"metadata": {},
|
341 |
"outputs": [
|
342 |
{
|
|
|
433 |
" <td>NaN</td>\n",
|
434 |
" <td>SFR</td>\n",
|
435 |
" <td>2018-01-27</td>\n",
|
436 |
+
" <td>13998.585612</td>\n",
|
437 |
" <td>0.047930</td>\n",
|
438 |
" <td>13998.585612</td>\n",
|
439 |
" <td>NaN</td>\n",
|
|
|
449 |
" <td>NaN</td>\n",
|
450 |
" <td>SFR</td>\n",
|
451 |
" <td>2018-02-03</td>\n",
|
452 |
+
" <td>14120.035549</td>\n",
|
453 |
" <td>0.047622</td>\n",
|
454 |
" <td>14120.035549</td>\n",
|
455 |
+
" <td>0.047622</td>\n",
|
456 |
" <td>NaN</td>\n",
|
457 |
" <td>NaN</td>\n",
|
458 |
" </tr>\n",
|
|
|
588 |
"0 NaN NaN \n",
|
589 |
"1 NaN 0.049042 \n",
|
590 |
"2 NaN 0.044740 \n",
|
591 |
+
"3 13998.585612 0.047930 \n",
|
592 |
+
"4 14120.035549 0.047622 \n",
|
593 |
"... ... ... \n",
|
594 |
"586709 NaN 0.094017 \n",
|
595 |
"586710 NaN 0.070175 \n",
|
|
|
602 |
"1 14114.788383 NaN \n",
|
603 |
"2 14326.128956 NaN \n",
|
604 |
"3 13998.585612 NaN \n",
|
605 |
+
"4 14120.035549 0.047622 \n",
|
606 |
"... ... ... \n",
|
607 |
"586709 NaN 0.037378 \n",
|
608 |
"586710 NaN 0.043203 \n",
|
|
|
626 |
"[586714 rows x 13 columns]"
|
627 |
]
|
628 |
},
|
629 |
+
"execution_count": 9,
|
630 |
"metadata": {},
|
631 |
"output_type": "execute_result"
|
632 |
}
|
|
|
648 |
},
|
649 |
{
|
650 |
"cell_type": "code",
|
651 |
+
"execution_count": 5,
|
652 |
"metadata": {},
|
653 |
"outputs": [],
|
654 |
"source": [
|
processors/for_sale_listings.ipynb
CHANGED
@@ -9,7 +9,12 @@
|
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
-
"from helpers import
|
|
|
|
|
|
|
|
|
|
|
13 |
]
|
14 |
},
|
15 |
{
|
@@ -340,8 +345,6 @@
|
|
340 |
}
|
341 |
],
|
342 |
"source": [
|
343 |
-
"# base cols RegionID,SizeRank,RegionName,RegionType,StateName\n",
|
344 |
-
"\n",
|
345 |
"exclude_columns = [\n",
|
346 |
" \"RegionID\",\n",
|
347 |
" \"SizeRank\",\n",
|
@@ -376,21 +379,9 @@
|
|
376 |
" elif \"condo\" in filename:\n",
|
377 |
" cur_df[\"Home Type\"] = \"condo/co-op only\"\n",
|
378 |
"\n",
|
379 |
-
"
|
380 |
-
"
|
381 |
-
"\n",
|
382 |
-
" for slug, col_name in slug_column_mappings.items():\n",
|
383 |
-
" if slug in filename:\n",
|
384 |
-
" cur_df = get_df(\n",
|
385 |
-
" cur_df,\n",
|
386 |
-
" exclude_columns,\n",
|
387 |
-
" columns_to_pivot,\n",
|
388 |
-
" col_name,\n",
|
389 |
-
" filename,\n",
|
390 |
-
" )\n",
|
391 |
-
"\n",
|
392 |
-
" data_frames.append(cur_df)\n",
|
393 |
-
" break\n",
|
394 |
"\n",
|
395 |
"\n",
|
396 |
"combined_df = get_combined_df(\n",
|
@@ -406,18 +397,7 @@
|
|
406 |
" ],\n",
|
407 |
")\n",
|
408 |
"\n",
|
409 |
-
"\n",
|
410 |
-
"# iterate over rows of combined df and coalesce column values across columns that start with \"Median Sale Price\"\n",
|
411 |
-
"columns_to_coalesce = [\n",
|
412 |
-
" \"Median Listing Price\",\n",
|
413 |
-
" \"Median Listing Price (Smoothed)\",\n",
|
414 |
-
" \"New Listings\",\n",
|
415 |
-
" \"New Listings (Smoothed)\",\n",
|
416 |
-
" \"New Pending (Smoothed)\",\n",
|
417 |
-
" \"New Pending\",\n",
|
418 |
-
"]\n",
|
419 |
-
"\n",
|
420 |
-
"combined_df = coalesce_columns(combined_df, columns_to_coalesce)\n",
|
421 |
"\n",
|
422 |
"combined_df"
|
423 |
]
|
|
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
+
"from helpers import (\n",
|
13 |
+
" get_combined_df,\n",
|
14 |
+
" coalesce_columns,\n",
|
15 |
+
" save_final_df_as_jsonl,\n",
|
16 |
+
" handle_slug_column_mappings,\n",
|
17 |
+
")"
|
18 |
]
|
19 |
},
|
20 |
{
|
|
|
345 |
}
|
346 |
],
|
347 |
"source": [
|
|
|
|
|
348 |
"exclude_columns = [\n",
|
349 |
" \"RegionID\",\n",
|
350 |
" \"SizeRank\",\n",
|
|
|
379 |
" elif \"condo\" in filename:\n",
|
380 |
" cur_df[\"Home Type\"] = \"condo/co-op only\"\n",
|
381 |
"\n",
|
382 |
+
" data_frames = handle_slug_column_mappings(\n",
|
383 |
+
" data_frames, slug_column_mappings, exclude_columns, filename, cur_df\n",
|
384 |
+
" )\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
"\n",
|
386 |
"\n",
|
387 |
"combined_df = get_combined_df(\n",
|
|
|
397 |
" ],\n",
|
398 |
")\n",
|
399 |
"\n",
|
400 |
+
"combined_df = coalesce_columns(combined_df)\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
401 |
"\n",
|
402 |
"combined_df"
|
403 |
]
|
processors/helpers.py
CHANGED
@@ -22,7 +22,10 @@ def get_combined_df(data_frames, on):
|
|
22 |
return combined_df
|
23 |
|
24 |
|
25 |
-
def coalesce_columns(
|
|
|
|
|
|
|
26 |
for index, row in df.iterrows():
|
27 |
for col in df.columns:
|
28 |
for column_to_coalesce in columns_to_coalesce:
|
@@ -31,7 +34,7 @@ def coalesce_columns(df, columns_to_coalesce):
|
|
31 |
df.at[index, column_to_coalesce] = row[col]
|
32 |
|
33 |
# remove columns with underscores
|
34 |
-
combined_df = df[
|
35 |
return combined_df
|
36 |
|
37 |
|
@@ -67,3 +70,25 @@ def save_final_df_as_jsonl(FULL_PROCESSED_DIR_PATH, final_df):
|
|
67 |
final_df.to_json(
|
68 |
FULL_PROCESSED_DIR_PATH + "final.jsonl", orient="records", lines=True
|
69 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
return combined_df
|
23 |
|
24 |
|
25 |
+
def coalesce_columns(
|
26 |
+
df,
|
27 |
+
):
|
28 |
+
columns_to_coalesce = [col for col in df.columns if "_" not in col]
|
29 |
for index, row in df.iterrows():
|
30 |
for col in df.columns:
|
31 |
for column_to_coalesce in columns_to_coalesce:
|
|
|
34 |
df.at[index, column_to_coalesce] = row[col]
|
35 |
|
36 |
# remove columns with underscores
|
37 |
+
combined_df = df[columns_to_coalesce]
|
38 |
return combined_df
|
39 |
|
40 |
|
|
|
70 |
final_df.to_json(
|
71 |
FULL_PROCESSED_DIR_PATH + "final.jsonl", orient="records", lines=True
|
72 |
)
|
73 |
+
|
74 |
+
|
75 |
+
def handle_slug_column_mappings(
|
76 |
+
data_frames, slug_column_mappings, exclude_columns, filename, cur_df
|
77 |
+
):
|
78 |
+
# Identify columns to pivot
|
79 |
+
columns_to_pivot = [col for col in cur_df.columns if col not in exclude_columns]
|
80 |
+
|
81 |
+
for slug, col_name in slug_column_mappings.items():
|
82 |
+
if slug in filename:
|
83 |
+
cur_df = get_df(
|
84 |
+
cur_df,
|
85 |
+
exclude_columns,
|
86 |
+
columns_to_pivot,
|
87 |
+
col_name,
|
88 |
+
filename,
|
89 |
+
)
|
90 |
+
|
91 |
+
data_frames.append(cur_df)
|
92 |
+
break
|
93 |
+
|
94 |
+
return data_frames
|
processors/home_value_forecasts.ipynb
CHANGED
@@ -2,19 +2,19 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
-
"from helpers import save_final_df_as_jsonl"
|
13 |
]
|
14 |
},
|
15 |
{
|
16 |
"cell_type": "code",
|
17 |
-
"execution_count":
|
18 |
"metadata": {},
|
19 |
"outputs": [],
|
20 |
"source": [
|
@@ -27,7 +27,7 @@
|
|
27 |
},
|
28 |
{
|
29 |
"cell_type": "code",
|
30 |
-
"execution_count":
|
31 |
"metadata": {},
|
32 |
"outputs": [
|
33 |
{
|
@@ -66,114 +66,114 @@
|
|
66 |
" <th>RegionName</th>\n",
|
67 |
" <th>RegionType</th>\n",
|
68 |
" <th>StateName</th>\n",
|
69 |
-
" <th>BaseDate</th>\n",
|
70 |
-
" <th>Month Over Month % (Smoothed)</th>\n",
|
71 |
-
" <th>Quarter Over Quarter % (Smoothed)</th>\n",
|
72 |
-
" <th>Year Over Year % (Smoothed)</th>\n",
|
73 |
-
" <th>Month Over Month % (Raw)</th>\n",
|
74 |
-
" <th>Quarter Over Quarter % (Raw)</th>\n",
|
75 |
-
" <th>Year Over Year % (Raw)</th>\n",
|
76 |
" <th>State</th>\n",
|
77 |
" <th>City</th>\n",
|
78 |
" <th>Metro</th>\n",
|
79 |
" <th>CountyName</th>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
" </tr>\n",
|
81 |
" </thead>\n",
|
82 |
" <tbody>\n",
|
83 |
" <tr>\n",
|
84 |
" <th>0</th>\n",
|
85 |
-
" <td>
|
86 |
-
" <td>
|
87 |
-
" <td>
|
88 |
-
" <td>
|
89 |
-
" <td>
|
|
|
|
|
|
|
|
|
90 |
" <td>2023-12-31</td>\n",
|
91 |
-
" <td>0.1</td>\n",
|
92 |
-
" <td>0.4</td>\n",
|
93 |
-
" <td>3.5</td>\n",
|
94 |
-
" <td>-0.5</td>\n",
|
95 |
-
" <td>0.4</td>\n",
|
96 |
-
" <td>3.7</td>\n",
|
97 |
-
" <td>NaN</td>\n",
|
98 |
" <td>NaN</td>\n",
|
99 |
" <td>NaN</td>\n",
|
100 |
" <td>NaN</td>\n",
|
|
|
|
|
|
|
101 |
" </tr>\n",
|
102 |
" <tr>\n",
|
103 |
" <th>1</th>\n",
|
104 |
-
" <td>
|
105 |
-
" <td>
|
106 |
-
" <td>
|
107 |
-
" <td>
|
|
|
108 |
" <td>NY</td>\n",
|
|
|
|
|
|
|
109 |
" <td>2023-12-31</td>\n",
|
110 |
-
" <td>0.2</td>\n",
|
111 |
-
" <td>0.2</td>\n",
|
112 |
-
" <td>1.0</td>\n",
|
113 |
-
" <td>-0.7</td>\n",
|
114 |
-
" <td>-0.9</td>\n",
|
115 |
-
" <td>0.6</td>\n",
|
116 |
-
" <td>NaN</td>\n",
|
117 |
" <td>NaN</td>\n",
|
118 |
" <td>NaN</td>\n",
|
119 |
" <td>NaN</td>\n",
|
|
|
|
|
|
|
120 |
" </tr>\n",
|
121 |
" <tr>\n",
|
122 |
" <th>2</th>\n",
|
123 |
-
" <td>
|
124 |
-
" <td>
|
125 |
-
" <td>
|
126 |
-
" <td>
|
127 |
-
" <td>
|
|
|
|
|
|
|
|
|
128 |
" <td>2023-12-31</td>\n",
|
129 |
-
" <td
|
130 |
-
" <td
|
131 |
-
" <td>
|
132 |
" <td>-0.6</td>\n",
|
133 |
-
" <td>0.
|
134 |
-
" <td>
|
135 |
-
" <td>NaN</td>\n",
|
136 |
-
" <td>NaN</td>\n",
|
137 |
-
" <td>NaN</td>\n",
|
138 |
-
" <td>NaN</td>\n",
|
139 |
" </tr>\n",
|
140 |
" <tr>\n",
|
141 |
" <th>3</th>\n",
|
142 |
-
" <td>
|
143 |
-
" <td>
|
144 |
-
" <td>
|
145 |
-
" <td>
|
146 |
-
" <td>
|
|
|
|
|
|
|
|
|
147 |
" <td>2023-12-31</td>\n",
|
148 |
-
" <td>0.
|
149 |
-
" <td>0.
|
150 |
-
" <td>
|
151 |
-
" <td>-0.
|
152 |
-
" <td
|
153 |
-
" <td>
|
154 |
-
" <td>NaN</td>\n",
|
155 |
-
" <td>NaN</td>\n",
|
156 |
-
" <td>NaN</td>\n",
|
157 |
-
" <td>NaN</td>\n",
|
158 |
" </tr>\n",
|
159 |
" <tr>\n",
|
160 |
" <th>4</th>\n",
|
161 |
-
" <td>
|
162 |
-
" <td>
|
163 |
-
" <td>
|
164 |
-
" <td>
|
165 |
-
" <td>
|
|
|
|
|
|
|
|
|
166 |
" <td>2023-12-31</td>\n",
|
167 |
-
" <td>-0.1</td>\n",
|
168 |
-
" <td>0.0</td>\n",
|
169 |
-
" <td>3.2</td>\n",
|
170 |
-
" <td>-0.6</td>\n",
|
171 |
-
" <td>0.9</td>\n",
|
172 |
-
" <td>3.6</td>\n",
|
173 |
-
" <td>NaN</td>\n",
|
174 |
" <td>NaN</td>\n",
|
175 |
" <td>NaN</td>\n",
|
176 |
" <td>NaN</td>\n",
|
|
|
|
|
|
|
177 |
" </tr>\n",
|
178 |
" <tr>\n",
|
179 |
" <th>...</th>\n",
|
@@ -195,182 +195,195 @@
|
|
195 |
" <td>...</td>\n",
|
196 |
" </tr>\n",
|
197 |
" <tr>\n",
|
198 |
-
" <th>
|
199 |
-
" <td>
|
200 |
-
" <td>
|
201 |
-
" <td>
|
202 |
" <td>zip</td>\n",
|
203 |
-
" <td>
|
|
|
|
|
|
|
|
|
204 |
" <td>2023-12-31</td>\n",
|
205 |
-
" <td>
|
206 |
-
" <td>
|
207 |
-
" <td>
|
208 |
-
" <td>-0.
|
209 |
-
" <td
|
210 |
-
" <td>2.
|
211 |
-
" <td>MN</td>\n",
|
212 |
-
" <td>Warsaw</td>\n",
|
213 |
-
" <td>Faribault-Northfield, MN</td>\n",
|
214 |
-
" <td>Rice County</td>\n",
|
215 |
" </tr>\n",
|
216 |
" <tr>\n",
|
217 |
-
" <th>
|
218 |
-
" <td>
|
219 |
-
" <td>
|
220 |
-
" <td>
|
221 |
" <td>zip</td>\n",
|
222 |
-
" <td>
|
|
|
|
|
|
|
|
|
223 |
" <td>2023-12-31</td>\n",
|
224 |
-
" <td>0.9</td>\n",
|
225 |
-
" <td>0.4</td>\n",
|
226 |
-
" <td>3.7</td>\n",
|
227 |
-
" <td>-0.7</td>\n",
|
228 |
-
" <td>0.4</td>\n",
|
229 |
-
" <td>2.3</td>\n",
|
230 |
-
" <td>IL</td>\n",
|
231 |
" <td>NaN</td>\n",
|
232 |
-
" <td>
|
233 |
-
" <td>
|
|
|
|
|
|
|
234 |
" </tr>\n",
|
235 |
" <tr>\n",
|
236 |
-
" <th>
|
237 |
-
" <td>
|
238 |
-
" <td>
|
239 |
-
" <td>
|
240 |
" <td>zip</td>\n",
|
241 |
-
" <td>
|
|
|
|
|
|
|
|
|
242 |
" <td>2023-12-31</td>\n",
|
243 |
-
" <td>-0.5</td>\n",
|
244 |
-
" <td>0.3</td>\n",
|
245 |
-
" <td>-0.6</td>\n",
|
246 |
-
" <td>-0.4</td>\n",
|
247 |
-
" <td>0.0</td>\n",
|
248 |
-
" <td>1.2</td>\n",
|
249 |
-
" <td>TX</td>\n",
|
250 |
" <td>NaN</td>\n",
|
251 |
-
" <td>
|
252 |
-
" <td>
|
|
|
|
|
|
|
253 |
" </tr>\n",
|
254 |
" <tr>\n",
|
255 |
-
" <th>
|
256 |
-
" <td>
|
257 |
" <td>39992</td>\n",
|
258 |
-
" <td>
|
259 |
" <td>zip</td>\n",
|
260 |
-
" <td>
|
|
|
|
|
|
|
|
|
261 |
" <td>2023-12-31</td>\n",
|
262 |
-
" <td
|
263 |
-
" <td
|
264 |
-
" <td
|
265 |
-
" <td>-
|
266 |
-
" <td
|
267 |
-
" <td
|
268 |
-
" <td>TX</td>\n",
|
269 |
-
" <td>NaN</td>\n",
|
270 |
-
" <td>Borger, TX</td>\n",
|
271 |
-
" <td>Hutchinson County</td>\n",
|
272 |
" </tr>\n",
|
273 |
" <tr>\n",
|
274 |
-
" <th>
|
275 |
-
" <td>
|
276 |
-
" <td>
|
277 |
-
" <td>
|
278 |
" <td>zip</td>\n",
|
279 |
-
" <td>
|
|
|
|
|
|
|
|
|
280 |
" <td>2023-12-31</td>\n",
|
281 |
-
" <td
|
282 |
-
" <td
|
283 |
-
" <td>
|
284 |
-
" <td>-0.
|
285 |
-
" <td
|
286 |
-
" <td
|
287 |
-
" <td>CA</td>\n",
|
288 |
-
" <td>Camp Meeker</td>\n",
|
289 |
-
" <td>Santa Rosa-Petaluma, CA</td>\n",
|
290 |
-
" <td>Sonoma County</td>\n",
|
291 |
" </tr>\n",
|
292 |
" </tbody>\n",
|
293 |
"</table>\n",
|
294 |
-
"<p>
|
295 |
"</div>"
|
296 |
],
|
297 |
"text/plain": [
|
298 |
-
" RegionID SizeRank
|
299 |
-
"0
|
300 |
-
"1
|
301 |
-
"2
|
302 |
-
"3
|
303 |
-
"4
|
304 |
-
"... ... ...
|
305 |
-
"
|
306 |
-
"
|
307 |
-
"
|
308 |
-
"
|
309 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
"\n",
|
311 |
-
"
|
312 |
-
"0
|
313 |
-
"1
|
314 |
-
"2
|
315 |
-
"3
|
316 |
-
"4
|
317 |
-
"...
|
318 |
-
"
|
319 |
-
"
|
320 |
-
"
|
321 |
-
"
|
322 |
-
"
|
323 |
"\n",
|
324 |
-
"
|
325 |
-
"0
|
326 |
-
"1
|
327 |
-
"2
|
328 |
-
"3
|
329 |
-
"4
|
330 |
-
"...
|
331 |
-
"
|
332 |
-
"
|
333 |
-
"
|
334 |
-
"
|
335 |
-
"
|
336 |
"\n",
|
337 |
-
"
|
338 |
-
"0
|
339 |
-
"1
|
340 |
-
"2
|
341 |
-
"3
|
342 |
-
"4
|
343 |
-
"...
|
344 |
-
"
|
345 |
-
"
|
346 |
-
"
|
347 |
-
"
|
348 |
-
"
|
349 |
"\n",
|
350 |
-
"
|
351 |
-
"0
|
352 |
-
"1
|
353 |
-
"2
|
354 |
-
"3
|
355 |
-
"4
|
356 |
-
"...
|
357 |
-
"
|
358 |
-
"
|
359 |
-
"
|
360 |
-
"
|
361 |
-
"
|
362 |
"\n",
|
363 |
-
"[
|
364 |
]
|
365 |
},
|
366 |
-
"execution_count":
|
367 |
"metadata": {},
|
368 |
"output_type": "execute_result"
|
369 |
}
|
370 |
],
|
371 |
"source": [
|
372 |
-
"
|
373 |
-
"
|
374 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
375 |
" if filename.endswith(\".csv\"):\n",
|
376 |
" print(\"processing \" + filename)\n",
|
@@ -380,47 +393,35 @@
|
|
380 |
" if filename.endswith(\"sm_sa_month.csv\"):\n",
|
381 |
" # print('Smoothed')\n",
|
382 |
" cur_df.columns = list(cur_df.columns[:-3]) + [\n",
|
383 |
-
" x + \" (Smoothed)\" for x in cols\n",
|
384 |
" ]\n",
|
385 |
" else:\n",
|
386 |
" # print('Raw')\n",
|
387 |
-
" cur_df.columns = list(cur_df.columns[:-3]) +
|
|
|
388 |
"\n",
|
389 |
-
"
|
390 |
-
" # print('Metro')\n",
|
391 |
-
" metro_data_frames.append(cur_df)\n",
|
392 |
"\n",
|
393 |
-
" elif filename.startswith(\"Zip\"):\n",
|
394 |
-
" # print('Zip')\n",
|
395 |
-
" zip_data_frames.append(cur_df)\n",
|
396 |
-
"\n",
|
397 |
-
"\n",
|
398 |
-
"def get_combined_df(data_frames):\n",
|
399 |
-
" combined_df = None\n",
|
400 |
-
" if len(data_frames) > 1:\n",
|
401 |
-
" # iterate over dataframes and merge them\n",
|
402 |
-
" final_df = data_frames[0]\n",
|
403 |
-
" for i in range(1, len(data_frames)):\n",
|
404 |
-
" cur_df = data_frames[i]\n",
|
405 |
-
" cols = list(cur_df.columns[-3:])\n",
|
406 |
-
" cols.append(\"RegionID\")\n",
|
407 |
-
" combined_df = pd.merge(final_df, cur_df[cols], on=\"RegionID\")\n",
|
408 |
-
" elif len(data_frames) == 1:\n",
|
409 |
-
" combined_df = data_frames[0]\n",
|
410 |
-
"\n",
|
411 |
-
" return combined_df\n",
|
412 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
413 |
"\n",
|
414 |
-
"
|
415 |
-
"combined_zip_dfs = get_combined_df(zip_data_frames)\n",
|
416 |
"\n",
|
417 |
-
"combined_df = pd.concat([combined_metro_dfs, combined_zip_dfs])\n",
|
418 |
"combined_df"
|
419 |
]
|
420 |
},
|
421 |
{
|
422 |
"cell_type": "code",
|
423 |
-
"execution_count":
|
424 |
"metadata": {},
|
425 |
"outputs": [
|
426 |
{
|
@@ -445,112 +446,112 @@
|
|
445 |
" <tr style=\"text-align: right;\">\n",
|
446 |
" <th></th>\n",
|
447 |
" <th>Region ID</th>\n",
|
|
|
448 |
" <th>Region</th>\n",
|
449 |
" <th>RegionType</th>\n",
|
450 |
-
" <th>Size Rank</th>\n",
|
451 |
" <th>State</th>\n",
|
452 |
" <th>City</th>\n",
|
453 |
" <th>Metro</th>\n",
|
454 |
" <th>County</th>\n",
|
455 |
" <th>Date</th>\n",
|
456 |
-
" <th>Month Over Month % (Smoothed)</th>\n",
|
457 |
-
" <th>Quarter Over Quarter % (Smoothed)</th>\n",
|
458 |
-
" <th>Year Over Year % (Smoothed)</th>\n",
|
459 |
-
" <th>Month Over Month
|
460 |
-
" <th>Quarter Over Quarter
|
461 |
-
" <th>Year Over Year
|
462 |
" </tr>\n",
|
463 |
" </thead>\n",
|
464 |
" <tbody>\n",
|
465 |
" <tr>\n",
|
466 |
" <th>0</th>\n",
|
467 |
-
" <td>
|
468 |
-
" <td>
|
469 |
-
" <td>
|
470 |
-
" <td>
|
471 |
-
" <td>
|
|
|
|
|
|
|
|
|
472 |
" <td>NaN</td>\n",
|
473 |
" <td>NaN</td>\n",
|
474 |
" <td>NaN</td>\n",
|
475 |
-
" <td
|
476 |
-
" <td
|
477 |
-
" <td>0.
|
478 |
-
" <td>3.5</td>\n",
|
479 |
-
" <td>-0.5</td>\n",
|
480 |
-
" <td>0.4</td>\n",
|
481 |
-
" <td>3.7</td>\n",
|
482 |
" </tr>\n",
|
483 |
" <tr>\n",
|
484 |
" <th>1</th>\n",
|
485 |
-
" <td>
|
486 |
-
" <td>
|
487 |
-
" <td>
|
488 |
-
" <td>
|
489 |
" <td>NY</td>\n",
|
490 |
-
" <td>
|
|
|
|
|
|
|
|
|
491 |
" <td>NaN</td>\n",
|
492 |
" <td>NaN</td>\n",
|
493 |
-
" <td>2023-12-31</td>\n",
|
494 |
-
" <td>0.2</td>\n",
|
495 |
-
" <td>0.2</td>\n",
|
496 |
-
" <td>1.0</td>\n",
|
497 |
" <td>-0.7</td>\n",
|
498 |
" <td>-0.9</td>\n",
|
499 |
" <td>0.6</td>\n",
|
500 |
" </tr>\n",
|
501 |
" <tr>\n",
|
502 |
" <th>2</th>\n",
|
503 |
-
" <td>
|
504 |
-
" <td>
|
505 |
-
" <td>
|
506 |
-
" <td>
|
507 |
-
" <td>
|
508 |
-
" <td>
|
509 |
-
" <td>
|
510 |
-
" <td>
|
511 |
" <td>2023-12-31</td>\n",
|
512 |
-
" <td
|
513 |
-
" <td
|
514 |
-
" <td>
|
515 |
" <td>-0.6</td>\n",
|
516 |
-
" <td>0.
|
517 |
-
" <td>
|
518 |
" </tr>\n",
|
519 |
" <tr>\n",
|
520 |
" <th>3</th>\n",
|
521 |
-
" <td>
|
522 |
-
" <td>
|
523 |
-
" <td>
|
524 |
-
" <td>
|
525 |
-
" <td>
|
526 |
-
" <td>
|
527 |
-
" <td>
|
528 |
-
" <td>
|
529 |
" <td>2023-12-31</td>\n",
|
530 |
-
" <td>0.
|
531 |
-
" <td>0.
|
532 |
-
" <td>
|
533 |
-
" <td>-0.
|
534 |
-
" <td
|
535 |
-
" <td>
|
536 |
" </tr>\n",
|
537 |
" <tr>\n",
|
538 |
" <th>4</th>\n",
|
539 |
-
" <td>
|
540 |
-
" <td>
|
541 |
-
" <td>
|
542 |
-
" <td>
|
543 |
-
" <td>
|
544 |
-
" <td>
|
|
|
|
|
|
|
545 |
" <td>NaN</td>\n",
|
546 |
" <td>NaN</td>\n",
|
547 |
-
" <td>
|
548 |
-
" <td>-0.
|
549 |
" <td>0.0</td>\n",
|
550 |
-
" <td>3.
|
551 |
-
" <td>-0.6</td>\n",
|
552 |
-
" <td>0.9</td>\n",
|
553 |
-
" <td>3.6</td>\n",
|
554 |
" </tr>\n",
|
555 |
" <tr>\n",
|
556 |
" <th>...</th>\n",
|
@@ -571,193 +572,191 @@
|
|
571 |
" <td>...</td>\n",
|
572 |
" </tr>\n",
|
573 |
" <tr>\n",
|
574 |
-
" <th>
|
575 |
-
" <td>
|
576 |
-
" <td>
|
|
|
577 |
" <td>zip</td>\n",
|
578 |
-
" <td>
|
579 |
-
" <td>
|
580 |
-
" <td>
|
581 |
-
" <td>
|
582 |
-
" <td>Rice County</td>\n",
|
583 |
" <td>2023-12-31</td>\n",
|
584 |
-
" <td>
|
585 |
-
" <td>
|
586 |
-
" <td>
|
587 |
-
" <td>-0.
|
588 |
-
" <td
|
589 |
-
" <td>2.
|
590 |
" </tr>\n",
|
591 |
" <tr>\n",
|
592 |
-
" <th>
|
593 |
-
" <td>
|
594 |
-
" <td>
|
|
|
595 |
" <td>zip</td>\n",
|
596 |
-
" <td>
|
597 |
-
" <td>
|
598 |
-
" <td>
|
599 |
-
" <td>
|
600 |
-
" <td>Macoupin County</td>\n",
|
601 |
" <td>2023-12-31</td>\n",
|
602 |
-
" <td>
|
603 |
-
" <td>
|
604 |
-
" <td>
|
605 |
" <td>-0.7</td>\n",
|
606 |
-
" <td
|
607 |
-
" <td>
|
608 |
" </tr>\n",
|
609 |
" <tr>\n",
|
610 |
-
" <th>
|
611 |
-
" <td>
|
612 |
-
" <td>
|
|
|
613 |
" <td>zip</td>\n",
|
614 |
-
" <td>
|
615 |
-
" <td>
|
616 |
-
" <td>
|
617 |
-
" <td>
|
618 |
-
" <td>Chambers County</td>\n",
|
619 |
" <td>2023-12-31</td>\n",
|
620 |
-
" <td
|
621 |
-
" <td>
|
622 |
-
" <td
|
623 |
-
" <td>-0
|
624 |
" <td>0.0</td>\n",
|
625 |
-
" <td>
|
626 |
" </tr>\n",
|
627 |
" <tr>\n",
|
628 |
-
" <th>
|
629 |
-
" <td>
|
630 |
-
" <td>79078</td>\n",
|
631 |
-
" <td>zip</td>\n",
|
632 |
" <td>39992</td>\n",
|
633 |
-
" <td>
|
634 |
-
" <td>
|
635 |
-
" <td>
|
636 |
-
" <td>
|
|
|
|
|
637 |
" <td>2023-12-31</td>\n",
|
638 |
-
" <td
|
639 |
-
" <td
|
640 |
-
" <td
|
641 |
-
" <td>-
|
642 |
-
" <td
|
643 |
-
" <td
|
644 |
" </tr>\n",
|
645 |
" <tr>\n",
|
646 |
-
" <th>
|
647 |
-
" <td>
|
648 |
-
" <td>
|
|
|
649 |
" <td>zip</td>\n",
|
650 |
-
" <td>
|
651 |
-
" <td>
|
652 |
-
" <td>
|
653 |
-
" <td>
|
654 |
-
" <td>Sonoma County</td>\n",
|
655 |
" <td>2023-12-31</td>\n",
|
656 |
-
" <td
|
657 |
-
" <td
|
658 |
-
" <td>
|
659 |
-
" <td>-0.
|
660 |
-
" <td
|
661 |
-
" <td
|
662 |
" </tr>\n",
|
663 |
" </tbody>\n",
|
664 |
"</table>\n",
|
665 |
-
"<p>
|
666 |
"</div>"
|
667 |
],
|
668 |
"text/plain": [
|
669 |
-
" Region ID
|
670 |
-
"0
|
671 |
-
"1
|
672 |
-
"2
|
673 |
-
"3
|
674 |
-
"4
|
675 |
-
"... ...
|
676 |
-
"
|
677 |
-
"
|
678 |
-
"
|
679 |
-
"
|
680 |
-
"
|
681 |
"\n",
|
682 |
-
"
|
683 |
-
"0
|
684 |
-
"1
|
685 |
-
"2
|
686 |
-
"3
|
687 |
-
"4
|
688 |
-
"...
|
689 |
-
"
|
690 |
-
"
|
691 |
-
"
|
692 |
-
"
|
693 |
-
"
|
694 |
"\n",
|
695 |
-
"
|
696 |
-
"0
|
697 |
-
"1
|
698 |
-
"2
|
699 |
-
"3
|
700 |
-
"4
|
701 |
-
"...
|
702 |
-
"
|
703 |
-
"
|
704 |
-
"
|
705 |
-
"
|
706 |
-
"
|
707 |
"\n",
|
708 |
-
"
|
709 |
-
"0
|
710 |
-
"1
|
711 |
-
"2
|
712 |
-
"3
|
713 |
-
"4
|
714 |
-
"...
|
715 |
-
"
|
716 |
-
"
|
717 |
-
"
|
718 |
-
"
|
719 |
-
"
|
720 |
"\n",
|
721 |
-
"
|
722 |
-
"0
|
723 |
-
"1
|
724 |
-
"2
|
725 |
-
"3
|
726 |
-
"4
|
727 |
-
"...
|
728 |
-
"
|
729 |
-
"
|
730 |
-
"
|
731 |
-
"
|
732 |
-
"
|
733 |
"\n",
|
734 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
735 |
]
|
736 |
},
|
737 |
-
"execution_count":
|
738 |
"metadata": {},
|
739 |
"output_type": "execute_result"
|
740 |
}
|
741 |
],
|
742 |
"source": [
|
743 |
-
"
|
744 |
-
"
|
745 |
-
"\n",
|
746 |
-
"all_cols = [\n",
|
747 |
-
" \"RegionID\",\n",
|
748 |
-
" \"RegionName\",\n",
|
749 |
-
" \"RegionType\",\n",
|
750 |
-
" \"SizeRank\",\n",
|
751 |
-
" \"StateName\",\n",
|
752 |
-
" \"State\",\n",
|
753 |
-
" \"City\",\n",
|
754 |
-
" \"Metro\",\n",
|
755 |
-
" \"CountyName\",\n",
|
756 |
-
" \"BaseDate\",\n",
|
757 |
-
"] + result_cols\n",
|
758 |
-
"\n",
|
759 |
-
"final_df = combined_df[all_cols]\n",
|
760 |
-
"final_df = final_df.drop(\"StateName\", axis=1)\n",
|
761 |
"final_df = final_df.rename(\n",
|
762 |
" columns={\n",
|
763 |
" \"CountyName\": \"County\",\n",
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
+
"from helpers import get_combined_df, coalesce_columns, save_final_df_as_jsonl"
|
13 |
]
|
14 |
},
|
15 |
{
|
16 |
"cell_type": "code",
|
17 |
+
"execution_count": 2,
|
18 |
"metadata": {},
|
19 |
"outputs": [],
|
20 |
"source": [
|
|
|
27 |
},
|
28 |
{
|
29 |
"cell_type": "code",
|
30 |
+
"execution_count": 3,
|
31 |
"metadata": {},
|
32 |
"outputs": [
|
33 |
{
|
|
|
66 |
" <th>RegionName</th>\n",
|
67 |
" <th>RegionType</th>\n",
|
68 |
" <th>StateName</th>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
" <th>State</th>\n",
|
70 |
" <th>City</th>\n",
|
71 |
" <th>Metro</th>\n",
|
72 |
" <th>CountyName</th>\n",
|
73 |
+
" <th>BaseDate</th>\n",
|
74 |
+
" <th>Month Over Month % (Smoothed) (Seaonally Adjusted)</th>\n",
|
75 |
+
" <th>Quarter Over Quarter % (Smoothed) (Seaonally Adjusted)</th>\n",
|
76 |
+
" <th>Year Over Year % (Smoothed) (Seaonally Adjusted)</th>\n",
|
77 |
+
" <th>Month Over Month %</th>\n",
|
78 |
+
" <th>Quarter Over Quarter %</th>\n",
|
79 |
+
" <th>Year Over Year %</th>\n",
|
80 |
" </tr>\n",
|
81 |
" </thead>\n",
|
82 |
" <tbody>\n",
|
83 |
" <tr>\n",
|
84 |
" <th>0</th>\n",
|
85 |
+
" <td>58001</td>\n",
|
86 |
+
" <td>30490</td>\n",
|
87 |
+
" <td>501</td>\n",
|
88 |
+
" <td>zip</td>\n",
|
89 |
+
" <td>NY</td>\n",
|
90 |
+
" <td>NY</td>\n",
|
91 |
+
" <td>Holtsville</td>\n",
|
92 |
+
" <td>New York-Newark-Jersey City, NY-NJ-PA</td>\n",
|
93 |
+
" <td>Suffolk County</td>\n",
|
94 |
" <td>2023-12-31</td>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
" <td>NaN</td>\n",
|
96 |
" <td>NaN</td>\n",
|
97 |
" <td>NaN</td>\n",
|
98 |
+
" <td>-0.7</td>\n",
|
99 |
+
" <td>-0.9</td>\n",
|
100 |
+
" <td>0.6</td>\n",
|
101 |
" </tr>\n",
|
102 |
" <tr>\n",
|
103 |
" <th>1</th>\n",
|
104 |
+
" <td>58002</td>\n",
|
105 |
+
" <td>30490</td>\n",
|
106 |
+
" <td>544</td>\n",
|
107 |
+
" <td>zip</td>\n",
|
108 |
+
" <td>NY</td>\n",
|
109 |
" <td>NY</td>\n",
|
110 |
+
" <td>Holtsville</td>\n",
|
111 |
+
" <td>New York-Newark-Jersey City, NY-NJ-PA</td>\n",
|
112 |
+
" <td>Suffolk County</td>\n",
|
113 |
" <td>2023-12-31</td>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
" <td>NaN</td>\n",
|
115 |
" <td>NaN</td>\n",
|
116 |
" <td>NaN</td>\n",
|
117 |
+
" <td>-0.7</td>\n",
|
118 |
+
" <td>-0.9</td>\n",
|
119 |
+
" <td>0.6</td>\n",
|
120 |
" </tr>\n",
|
121 |
" <tr>\n",
|
122 |
" <th>2</th>\n",
|
123 |
+
" <td>58196</td>\n",
|
124 |
+
" <td>7440</td>\n",
|
125 |
+
" <td>1001</td>\n",
|
126 |
+
" <td>zip</td>\n",
|
127 |
+
" <td>MA</td>\n",
|
128 |
+
" <td>MA</td>\n",
|
129 |
+
" <td>Agawam</td>\n",
|
130 |
+
" <td>Springfield, MA</td>\n",
|
131 |
+
" <td>Hampden County</td>\n",
|
132 |
" <td>2023-12-31</td>\n",
|
133 |
+
" <td>0.4</td>\n",
|
134 |
+
" <td>0.9</td>\n",
|
135 |
+
" <td>3.2</td>\n",
|
136 |
" <td>-0.6</td>\n",
|
137 |
+
" <td>0.0</td>\n",
|
138 |
+
" <td>3.0</td>\n",
|
|
|
|
|
|
|
|
|
139 |
" </tr>\n",
|
140 |
" <tr>\n",
|
141 |
" <th>3</th>\n",
|
142 |
+
" <td>58197</td>\n",
|
143 |
+
" <td>3911</td>\n",
|
144 |
+
" <td>1002</td>\n",
|
145 |
+
" <td>zip</td>\n",
|
146 |
+
" <td>MA</td>\n",
|
147 |
+
" <td>MA</td>\n",
|
148 |
+
" <td>Amherst</td>\n",
|
149 |
+
" <td>Springfield, MA</td>\n",
|
150 |
+
" <td>Hampshire County</td>\n",
|
151 |
" <td>2023-12-31</td>\n",
|
152 |
+
" <td>0.2</td>\n",
|
153 |
+
" <td>0.7</td>\n",
|
154 |
+
" <td>2.7</td>\n",
|
155 |
+
" <td>-0.6</td>\n",
|
156 |
+
" <td>0.0</td>\n",
|
157 |
+
" <td>2.9</td>\n",
|
|
|
|
|
|
|
|
|
158 |
" </tr>\n",
|
159 |
" <tr>\n",
|
160 |
" <th>4</th>\n",
|
161 |
+
" <td>58198</td>\n",
|
162 |
+
" <td>8838</td>\n",
|
163 |
+
" <td>1003</td>\n",
|
164 |
+
" <td>zip</td>\n",
|
165 |
+
" <td>MA</td>\n",
|
166 |
+
" <td>MA</td>\n",
|
167 |
+
" <td>Amherst</td>\n",
|
168 |
+
" <td>Springfield, MA</td>\n",
|
169 |
+
" <td>Hampshire County</td>\n",
|
170 |
" <td>2023-12-31</td>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
" <td>NaN</td>\n",
|
172 |
" <td>NaN</td>\n",
|
173 |
" <td>NaN</td>\n",
|
174 |
+
" <td>-0.7</td>\n",
|
175 |
+
" <td>0.0</td>\n",
|
176 |
+
" <td>3.4</td>\n",
|
177 |
" </tr>\n",
|
178 |
" <tr>\n",
|
179 |
" <th>...</th>\n",
|
|
|
195 |
" <td>...</td>\n",
|
196 |
" </tr>\n",
|
197 |
" <tr>\n",
|
198 |
+
" <th>31849</th>\n",
|
199 |
+
" <td>827279</td>\n",
|
200 |
+
" <td>7779</td>\n",
|
201 |
+
" <td>72405</td>\n",
|
202 |
" <td>zip</td>\n",
|
203 |
+
" <td>AR</td>\n",
|
204 |
+
" <td>AR</td>\n",
|
205 |
+
" <td>Jonesboro</td>\n",
|
206 |
+
" <td>Jonesboro, AR</td>\n",
|
207 |
+
" <td>Craighead County</td>\n",
|
208 |
" <td>2023-12-31</td>\n",
|
209 |
+
" <td>NaN</td>\n",
|
210 |
+
" <td>NaN</td>\n",
|
211 |
+
" <td>NaN</td>\n",
|
212 |
+
" <td>-0.7</td>\n",
|
213 |
+
" <td>0.0</td>\n",
|
214 |
+
" <td>2.5</td>\n",
|
|
|
|
|
|
|
|
|
215 |
" </tr>\n",
|
216 |
" <tr>\n",
|
217 |
+
" <th>31850</th>\n",
|
218 |
+
" <td>834213</td>\n",
|
219 |
+
" <td>30490</td>\n",
|
220 |
+
" <td>11437</td>\n",
|
221 |
" <td>zip</td>\n",
|
222 |
+
" <td>NY</td>\n",
|
223 |
+
" <td>NY</td>\n",
|
224 |
+
" <td>New York</td>\n",
|
225 |
+
" <td>New York-Newark-Jersey City, NY-NJ-PA</td>\n",
|
226 |
+
" <td>Queens County</td>\n",
|
227 |
" <td>2023-12-31</td>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
" <td>NaN</td>\n",
|
229 |
+
" <td>NaN</td>\n",
|
230 |
+
" <td>NaN</td>\n",
|
231 |
+
" <td>-0.7</td>\n",
|
232 |
+
" <td>-0.9</td>\n",
|
233 |
+
" <td>0.6</td>\n",
|
234 |
" </tr>\n",
|
235 |
" <tr>\n",
|
236 |
+
" <th>31851</th>\n",
|
237 |
+
" <td>845914</td>\n",
|
238 |
+
" <td>6361</td>\n",
|
239 |
+
" <td>85288</td>\n",
|
240 |
" <td>zip</td>\n",
|
241 |
+
" <td>AZ</td>\n",
|
242 |
+
" <td>AZ</td>\n",
|
243 |
+
" <td>Tempe</td>\n",
|
244 |
+
" <td>Phoenix-Mesa-Chandler, AZ</td>\n",
|
245 |
+
" <td>Maricopa County</td>\n",
|
246 |
" <td>2023-12-31</td>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
" <td>NaN</td>\n",
|
248 |
+
" <td>NaN</td>\n",
|
249 |
+
" <td>NaN</td>\n",
|
250 |
+
" <td>-1.0</td>\n",
|
251 |
+
" <td>0.0</td>\n",
|
252 |
+
" <td>4.5</td>\n",
|
253 |
" </tr>\n",
|
254 |
" <tr>\n",
|
255 |
+
" <th>31852</th>\n",
|
256 |
+
" <td>847854</td>\n",
|
257 |
" <td>39992</td>\n",
|
258 |
+
" <td>20598</td>\n",
|
259 |
" <td>zip</td>\n",
|
260 |
+
" <td>VA</td>\n",
|
261 |
+
" <td>VA</td>\n",
|
262 |
+
" <td>Arlington</td>\n",
|
263 |
+
" <td>Washington-Arlington-Alexandria, DC-VA-MD-WV</td>\n",
|
264 |
+
" <td>Arlington County</td>\n",
|
265 |
" <td>2023-12-31</td>\n",
|
266 |
+
" <td>NaN</td>\n",
|
267 |
+
" <td>NaN</td>\n",
|
268 |
+
" <td>NaN</td>\n",
|
269 |
+
" <td>-0.4</td>\n",
|
270 |
+
" <td>0.9</td>\n",
|
271 |
+
" <td>1.2</td>\n",
|
|
|
|
|
|
|
|
|
272 |
" </tr>\n",
|
273 |
" <tr>\n",
|
274 |
+
" <th>31853</th>\n",
|
275 |
+
" <td>847855</td>\n",
|
276 |
+
" <td>30490</td>\n",
|
277 |
+
" <td>34249</td>\n",
|
278 |
" <td>zip</td>\n",
|
279 |
+
" <td>FL</td>\n",
|
280 |
+
" <td>FL</td>\n",
|
281 |
+
" <td>Sarasota</td>\n",
|
282 |
+
" <td>North Port-Sarasota-Bradenton, FL</td>\n",
|
283 |
+
" <td>Sarasota County</td>\n",
|
284 |
" <td>2023-12-31</td>\n",
|
285 |
+
" <td>NaN</td>\n",
|
286 |
+
" <td>NaN</td>\n",
|
287 |
+
" <td>NaN</td>\n",
|
288 |
+
" <td>-0.9</td>\n",
|
289 |
+
" <td>-0.1</td>\n",
|
290 |
+
" <td>5.4</td>\n",
|
|
|
|
|
|
|
|
|
291 |
" </tr>\n",
|
292 |
" </tbody>\n",
|
293 |
"</table>\n",
|
294 |
+
"<p>31854 rows × 16 columns</p>\n",
|
295 |
"</div>"
|
296 |
],
|
297 |
"text/plain": [
|
298 |
+
" RegionID SizeRank RegionName RegionType StateName State City \\\n",
|
299 |
+
"0 58001 30490 501 zip NY NY Holtsville \n",
|
300 |
+
"1 58002 30490 544 zip NY NY Holtsville \n",
|
301 |
+
"2 58196 7440 1001 zip MA MA Agawam \n",
|
302 |
+
"3 58197 3911 1002 zip MA MA Amherst \n",
|
303 |
+
"4 58198 8838 1003 zip MA MA Amherst \n",
|
304 |
+
"... ... ... ... ... ... ... ... \n",
|
305 |
+
"31849 827279 7779 72405 zip AR AR Jonesboro \n",
|
306 |
+
"31850 834213 30490 11437 zip NY NY New York \n",
|
307 |
+
"31851 845914 6361 85288 zip AZ AZ Tempe \n",
|
308 |
+
"31852 847854 39992 20598 zip VA VA Arlington \n",
|
309 |
+
"31853 847855 30490 34249 zip FL FL Sarasota \n",
|
310 |
+
"\n",
|
311 |
+
" Metro CountyName \\\n",
|
312 |
+
"0 New York-Newark-Jersey City, NY-NJ-PA Suffolk County \n",
|
313 |
+
"1 New York-Newark-Jersey City, NY-NJ-PA Suffolk County \n",
|
314 |
+
"2 Springfield, MA Hampden County \n",
|
315 |
+
"3 Springfield, MA Hampshire County \n",
|
316 |
+
"4 Springfield, MA Hampshire County \n",
|
317 |
+
"... ... ... \n",
|
318 |
+
"31849 Jonesboro, AR Craighead County \n",
|
319 |
+
"31850 New York-Newark-Jersey City, NY-NJ-PA Queens County \n",
|
320 |
+
"31851 Phoenix-Mesa-Chandler, AZ Maricopa County \n",
|
321 |
+
"31852 Washington-Arlington-Alexandria, DC-VA-MD-WV Arlington County \n",
|
322 |
+
"31853 North Port-Sarasota-Bradenton, FL Sarasota County \n",
|
323 |
"\n",
|
324 |
+
" BaseDate Month Over Month % (Smoothed) (Seaonally Adjusted) \\\n",
|
325 |
+
"0 2023-12-31 NaN \n",
|
326 |
+
"1 2023-12-31 NaN \n",
|
327 |
+
"2 2023-12-31 0.4 \n",
|
328 |
+
"3 2023-12-31 0.2 \n",
|
329 |
+
"4 2023-12-31 NaN \n",
|
330 |
+
"... ... ... \n",
|
331 |
+
"31849 2023-12-31 NaN \n",
|
332 |
+
"31850 2023-12-31 NaN \n",
|
333 |
+
"31851 2023-12-31 NaN \n",
|
334 |
+
"31852 2023-12-31 NaN \n",
|
335 |
+
"31853 2023-12-31 NaN \n",
|
336 |
"\n",
|
337 |
+
" Quarter Over Quarter % (Smoothed) (Seaonally Adjusted) \\\n",
|
338 |
+
"0 NaN \n",
|
339 |
+
"1 NaN \n",
|
340 |
+
"2 0.9 \n",
|
341 |
+
"3 0.7 \n",
|
342 |
+
"4 NaN \n",
|
343 |
+
"... ... \n",
|
344 |
+
"31849 NaN \n",
|
345 |
+
"31850 NaN \n",
|
346 |
+
"31851 NaN \n",
|
347 |
+
"31852 NaN \n",
|
348 |
+
"31853 NaN \n",
|
349 |
"\n",
|
350 |
+
" Year Over Year % (Smoothed) (Seaonally Adjusted) Month Over Month % \\\n",
|
351 |
+
"0 NaN -0.7 \n",
|
352 |
+
"1 NaN -0.7 \n",
|
353 |
+
"2 3.2 -0.6 \n",
|
354 |
+
"3 2.7 -0.6 \n",
|
355 |
+
"4 NaN -0.7 \n",
|
356 |
+
"... ... ... \n",
|
357 |
+
"31849 NaN -0.7 \n",
|
358 |
+
"31850 NaN -0.7 \n",
|
359 |
+
"31851 NaN -1.0 \n",
|
360 |
+
"31852 NaN -0.4 \n",
|
361 |
+
"31853 NaN -0.9 \n",
|
362 |
"\n",
|
363 |
+
" Quarter Over Quarter % Year Over Year % \n",
|
364 |
+
"0 -0.9 0.6 \n",
|
365 |
+
"1 -0.9 0.6 \n",
|
366 |
+
"2 0.0 3.0 \n",
|
367 |
+
"3 0.0 2.9 \n",
|
368 |
+
"4 0.0 3.4 \n",
|
369 |
+
"... ... ... \n",
|
370 |
+
"31849 0.0 2.5 \n",
|
371 |
+
"31850 -0.9 0.6 \n",
|
372 |
+
"31851 0.0 4.5 \n",
|
373 |
+
"31852 0.9 1.2 \n",
|
374 |
+
"31853 -0.1 5.4 \n",
|
375 |
"\n",
|
376 |
+
"[31854 rows x 16 columns]"
|
377 |
]
|
378 |
},
|
379 |
+
"execution_count": 3,
|
380 |
"metadata": {},
|
381 |
"output_type": "execute_result"
|
382 |
}
|
383 |
],
|
384 |
"source": [
|
385 |
+
"data_frames = []\n",
|
386 |
+
"\n",
|
387 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
388 |
" if filename.endswith(\".csv\"):\n",
|
389 |
" print(\"processing \" + filename)\n",
|
|
|
393 |
" if filename.endswith(\"sm_sa_month.csv\"):\n",
|
394 |
" # print('Smoothed')\n",
|
395 |
" cur_df.columns = list(cur_df.columns[:-3]) + [\n",
|
396 |
+
" x + \" (Smoothed) (Seaonally Adjusted)\" for x in cols\n",
|
397 |
" ]\n",
|
398 |
" else:\n",
|
399 |
" # print('Raw')\n",
|
400 |
+
" cur_df.columns = list(cur_df.columns[:-3]) + cols\n",
|
401 |
+
" cur_df[\"RegionName\"] = cur_df[\"RegionName\"].astype(str)\n",
|
402 |
"\n",
|
403 |
+
" data_frames.append(cur_df)\n",
|
|
|
|
|
404 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
"\n",
|
406 |
+
"combined_df = get_combined_df(\n",
|
407 |
+
" data_frames,\n",
|
408 |
+
" [\n",
|
409 |
+
" \"RegionID\",\n",
|
410 |
+
" \"RegionType\",\n",
|
411 |
+
" \"SizeRank\",\n",
|
412 |
+
" \"StateName\",\n",
|
413 |
+
" \"BaseDate\",\n",
|
414 |
+
" ],\n",
|
415 |
+
")\n",
|
416 |
"\n",
|
417 |
+
"combined_df = coalesce_columns(combined_df)\n",
|
|
|
418 |
"\n",
|
|
|
419 |
"combined_df"
|
420 |
]
|
421 |
},
|
422 |
{
|
423 |
"cell_type": "code",
|
424 |
+
"execution_count": 4,
|
425 |
"metadata": {},
|
426 |
"outputs": [
|
427 |
{
|
|
|
446 |
" <tr style=\"text-align: right;\">\n",
|
447 |
" <th></th>\n",
|
448 |
" <th>Region ID</th>\n",
|
449 |
+
" <th>Size Rank</th>\n",
|
450 |
" <th>Region</th>\n",
|
451 |
" <th>RegionType</th>\n",
|
|
|
452 |
" <th>State</th>\n",
|
453 |
" <th>City</th>\n",
|
454 |
" <th>Metro</th>\n",
|
455 |
" <th>County</th>\n",
|
456 |
" <th>Date</th>\n",
|
457 |
+
" <th>Month Over Month % (Smoothed) (Seaonally Adjusted)</th>\n",
|
458 |
+
" <th>Quarter Over Quarter % (Smoothed) (Seaonally Adjusted)</th>\n",
|
459 |
+
" <th>Year Over Year % (Smoothed) (Seaonally Adjusted)</th>\n",
|
460 |
+
" <th>Month Over Month %</th>\n",
|
461 |
+
" <th>Quarter Over Quarter %</th>\n",
|
462 |
+
" <th>Year Over Year %</th>\n",
|
463 |
" </tr>\n",
|
464 |
" </thead>\n",
|
465 |
" <tbody>\n",
|
466 |
" <tr>\n",
|
467 |
" <th>0</th>\n",
|
468 |
+
" <td>58001</td>\n",
|
469 |
+
" <td>30490</td>\n",
|
470 |
+
" <td>501</td>\n",
|
471 |
+
" <td>zip</td>\n",
|
472 |
+
" <td>NY</td>\n",
|
473 |
+
" <td>Holtsville</td>\n",
|
474 |
+
" <td>New York-Newark-Jersey City, NY-NJ-PA</td>\n",
|
475 |
+
" <td>Suffolk County</td>\n",
|
476 |
+
" <td>2023-12-31</td>\n",
|
477 |
" <td>NaN</td>\n",
|
478 |
" <td>NaN</td>\n",
|
479 |
" <td>NaN</td>\n",
|
480 |
+
" <td>-0.7</td>\n",
|
481 |
+
" <td>-0.9</td>\n",
|
482 |
+
" <td>0.6</td>\n",
|
|
|
|
|
|
|
|
|
483 |
" </tr>\n",
|
484 |
" <tr>\n",
|
485 |
" <th>1</th>\n",
|
486 |
+
" <td>58002</td>\n",
|
487 |
+
" <td>30490</td>\n",
|
488 |
+
" <td>544</td>\n",
|
489 |
+
" <td>zip</td>\n",
|
490 |
" <td>NY</td>\n",
|
491 |
+
" <td>Holtsville</td>\n",
|
492 |
+
" <td>New York-Newark-Jersey City, NY-NJ-PA</td>\n",
|
493 |
+
" <td>Suffolk County</td>\n",
|
494 |
+
" <td>2023-12-31</td>\n",
|
495 |
+
" <td>NaN</td>\n",
|
496 |
" <td>NaN</td>\n",
|
497 |
" <td>NaN</td>\n",
|
|
|
|
|
|
|
|
|
498 |
" <td>-0.7</td>\n",
|
499 |
" <td>-0.9</td>\n",
|
500 |
" <td>0.6</td>\n",
|
501 |
" </tr>\n",
|
502 |
" <tr>\n",
|
503 |
" <th>2</th>\n",
|
504 |
+
" <td>58196</td>\n",
|
505 |
+
" <td>7440</td>\n",
|
506 |
+
" <td>1001</td>\n",
|
507 |
+
" <td>zip</td>\n",
|
508 |
+
" <td>MA</td>\n",
|
509 |
+
" <td>Agawam</td>\n",
|
510 |
+
" <td>Springfield, MA</td>\n",
|
511 |
+
" <td>Hampden County</td>\n",
|
512 |
" <td>2023-12-31</td>\n",
|
513 |
+
" <td>0.4</td>\n",
|
514 |
+
" <td>0.9</td>\n",
|
515 |
+
" <td>3.2</td>\n",
|
516 |
" <td>-0.6</td>\n",
|
517 |
+
" <td>0.0</td>\n",
|
518 |
+
" <td>3.0</td>\n",
|
519 |
" </tr>\n",
|
520 |
" <tr>\n",
|
521 |
" <th>3</th>\n",
|
522 |
+
" <td>58197</td>\n",
|
523 |
+
" <td>3911</td>\n",
|
524 |
+
" <td>1002</td>\n",
|
525 |
+
" <td>zip</td>\n",
|
526 |
+
" <td>MA</td>\n",
|
527 |
+
" <td>Amherst</td>\n",
|
528 |
+
" <td>Springfield, MA</td>\n",
|
529 |
+
" <td>Hampshire County</td>\n",
|
530 |
" <td>2023-12-31</td>\n",
|
531 |
+
" <td>0.2</td>\n",
|
532 |
+
" <td>0.7</td>\n",
|
533 |
+
" <td>2.7</td>\n",
|
534 |
+
" <td>-0.6</td>\n",
|
535 |
+
" <td>0.0</td>\n",
|
536 |
+
" <td>2.9</td>\n",
|
537 |
" </tr>\n",
|
538 |
" <tr>\n",
|
539 |
" <th>4</th>\n",
|
540 |
+
" <td>58198</td>\n",
|
541 |
+
" <td>8838</td>\n",
|
542 |
+
" <td>1003</td>\n",
|
543 |
+
" <td>zip</td>\n",
|
544 |
+
" <td>MA</td>\n",
|
545 |
+
" <td>Amherst</td>\n",
|
546 |
+
" <td>Springfield, MA</td>\n",
|
547 |
+
" <td>Hampshire County</td>\n",
|
548 |
+
" <td>2023-12-31</td>\n",
|
549 |
" <td>NaN</td>\n",
|
550 |
" <td>NaN</td>\n",
|
551 |
+
" <td>NaN</td>\n",
|
552 |
+
" <td>-0.7</td>\n",
|
553 |
" <td>0.0</td>\n",
|
554 |
+
" <td>3.4</td>\n",
|
|
|
|
|
|
|
555 |
" </tr>\n",
|
556 |
" <tr>\n",
|
557 |
" <th>...</th>\n",
|
|
|
572 |
" <td>...</td>\n",
|
573 |
" </tr>\n",
|
574 |
" <tr>\n",
|
575 |
+
" <th>31849</th>\n",
|
576 |
+
" <td>827279</td>\n",
|
577 |
+
" <td>7779</td>\n",
|
578 |
+
" <td>72405</td>\n",
|
579 |
" <td>zip</td>\n",
|
580 |
+
" <td>AR</td>\n",
|
581 |
+
" <td>Jonesboro</td>\n",
|
582 |
+
" <td>Jonesboro, AR</td>\n",
|
583 |
+
" <td>Craighead County</td>\n",
|
|
|
584 |
" <td>2023-12-31</td>\n",
|
585 |
+
" <td>NaN</td>\n",
|
586 |
+
" <td>NaN</td>\n",
|
587 |
+
" <td>NaN</td>\n",
|
588 |
+
" <td>-0.7</td>\n",
|
589 |
+
" <td>0.0</td>\n",
|
590 |
+
" <td>2.5</td>\n",
|
591 |
" </tr>\n",
|
592 |
" <tr>\n",
|
593 |
+
" <th>31850</th>\n",
|
594 |
+
" <td>834213</td>\n",
|
595 |
+
" <td>30490</td>\n",
|
596 |
+
" <td>11437</td>\n",
|
597 |
" <td>zip</td>\n",
|
598 |
+
" <td>NY</td>\n",
|
599 |
+
" <td>New York</td>\n",
|
600 |
+
" <td>New York-Newark-Jersey City, NY-NJ-PA</td>\n",
|
601 |
+
" <td>Queens County</td>\n",
|
|
|
602 |
" <td>2023-12-31</td>\n",
|
603 |
+
" <td>NaN</td>\n",
|
604 |
+
" <td>NaN</td>\n",
|
605 |
+
" <td>NaN</td>\n",
|
606 |
" <td>-0.7</td>\n",
|
607 |
+
" <td>-0.9</td>\n",
|
608 |
+
" <td>0.6</td>\n",
|
609 |
" </tr>\n",
|
610 |
" <tr>\n",
|
611 |
+
" <th>31851</th>\n",
|
612 |
+
" <td>845914</td>\n",
|
613 |
+
" <td>6361</td>\n",
|
614 |
+
" <td>85288</td>\n",
|
615 |
" <td>zip</td>\n",
|
616 |
+
" <td>AZ</td>\n",
|
617 |
+
" <td>Tempe</td>\n",
|
618 |
+
" <td>Phoenix-Mesa-Chandler, AZ</td>\n",
|
619 |
+
" <td>Maricopa County</td>\n",
|
|
|
620 |
" <td>2023-12-31</td>\n",
|
621 |
+
" <td>NaN</td>\n",
|
622 |
+
" <td>NaN</td>\n",
|
623 |
+
" <td>NaN</td>\n",
|
624 |
+
" <td>-1.0</td>\n",
|
625 |
" <td>0.0</td>\n",
|
626 |
+
" <td>4.5</td>\n",
|
627 |
" </tr>\n",
|
628 |
" <tr>\n",
|
629 |
+
" <th>31852</th>\n",
|
630 |
+
" <td>847854</td>\n",
|
|
|
|
|
631 |
" <td>39992</td>\n",
|
632 |
+
" <td>20598</td>\n",
|
633 |
+
" <td>zip</td>\n",
|
634 |
+
" <td>VA</td>\n",
|
635 |
+
" <td>Arlington</td>\n",
|
636 |
+
" <td>Washington-Arlington-Alexandria, DC-VA-MD-WV</td>\n",
|
637 |
+
" <td>Arlington County</td>\n",
|
638 |
" <td>2023-12-31</td>\n",
|
639 |
+
" <td>NaN</td>\n",
|
640 |
+
" <td>NaN</td>\n",
|
641 |
+
" <td>NaN</td>\n",
|
642 |
+
" <td>-0.4</td>\n",
|
643 |
+
" <td>0.9</td>\n",
|
644 |
+
" <td>1.2</td>\n",
|
645 |
" </tr>\n",
|
646 |
" <tr>\n",
|
647 |
+
" <th>31853</th>\n",
|
648 |
+
" <td>847855</td>\n",
|
649 |
+
" <td>30490</td>\n",
|
650 |
+
" <td>34249</td>\n",
|
651 |
" <td>zip</td>\n",
|
652 |
+
" <td>FL</td>\n",
|
653 |
+
" <td>Sarasota</td>\n",
|
654 |
+
" <td>North Port-Sarasota-Bradenton, FL</td>\n",
|
655 |
+
" <td>Sarasota County</td>\n",
|
|
|
656 |
" <td>2023-12-31</td>\n",
|
657 |
+
" <td>NaN</td>\n",
|
658 |
+
" <td>NaN</td>\n",
|
659 |
+
" <td>NaN</td>\n",
|
660 |
+
" <td>-0.9</td>\n",
|
661 |
+
" <td>-0.1</td>\n",
|
662 |
+
" <td>5.4</td>\n",
|
663 |
" </tr>\n",
|
664 |
" </tbody>\n",
|
665 |
"</table>\n",
|
666 |
+
"<p>31854 rows × 15 columns</p>\n",
|
667 |
"</div>"
|
668 |
],
|
669 |
"text/plain": [
|
670 |
+
" Region ID Size Rank Region RegionType State City \\\n",
|
671 |
+
"0 58001 30490 501 zip NY Holtsville \n",
|
672 |
+
"1 58002 30490 544 zip NY Holtsville \n",
|
673 |
+
"2 58196 7440 1001 zip MA Agawam \n",
|
674 |
+
"3 58197 3911 1002 zip MA Amherst \n",
|
675 |
+
"4 58198 8838 1003 zip MA Amherst \n",
|
676 |
+
"... ... ... ... ... ... ... \n",
|
677 |
+
"31849 827279 7779 72405 zip AR Jonesboro \n",
|
678 |
+
"31850 834213 30490 11437 zip NY New York \n",
|
679 |
+
"31851 845914 6361 85288 zip AZ Tempe \n",
|
680 |
+
"31852 847854 39992 20598 zip VA Arlington \n",
|
681 |
+
"31853 847855 30490 34249 zip FL Sarasota \n",
|
682 |
"\n",
|
683 |
+
" Metro County \\\n",
|
684 |
+
"0 New York-Newark-Jersey City, NY-NJ-PA Suffolk County \n",
|
685 |
+
"1 New York-Newark-Jersey City, NY-NJ-PA Suffolk County \n",
|
686 |
+
"2 Springfield, MA Hampden County \n",
|
687 |
+
"3 Springfield, MA Hampshire County \n",
|
688 |
+
"4 Springfield, MA Hampshire County \n",
|
689 |
+
"... ... ... \n",
|
690 |
+
"31849 Jonesboro, AR Craighead County \n",
|
691 |
+
"31850 New York-Newark-Jersey City, NY-NJ-PA Queens County \n",
|
692 |
+
"31851 Phoenix-Mesa-Chandler, AZ Maricopa County \n",
|
693 |
+
"31852 Washington-Arlington-Alexandria, DC-VA-MD-WV Arlington County \n",
|
694 |
+
"31853 North Port-Sarasota-Bradenton, FL Sarasota County \n",
|
695 |
"\n",
|
696 |
+
" Date Month Over Month % (Smoothed) (Seaonally Adjusted) \\\n",
|
697 |
+
"0 2023-12-31 NaN \n",
|
698 |
+
"1 2023-12-31 NaN \n",
|
699 |
+
"2 2023-12-31 0.4 \n",
|
700 |
+
"3 2023-12-31 0.2 \n",
|
701 |
+
"4 2023-12-31 NaN \n",
|
702 |
+
"... ... ... \n",
|
703 |
+
"31849 2023-12-31 NaN \n",
|
704 |
+
"31850 2023-12-31 NaN \n",
|
705 |
+
"31851 2023-12-31 NaN \n",
|
706 |
+
"31852 2023-12-31 NaN \n",
|
707 |
+
"31853 2023-12-31 NaN \n",
|
708 |
"\n",
|
709 |
+
" Quarter Over Quarter % (Smoothed) (Seaonally Adjusted) \\\n",
|
710 |
+
"0 NaN \n",
|
711 |
+
"1 NaN \n",
|
712 |
+
"2 0.9 \n",
|
713 |
+
"3 0.7 \n",
|
714 |
+
"4 NaN \n",
|
715 |
+
"... ... \n",
|
716 |
+
"31849 NaN \n",
|
717 |
+
"31850 NaN \n",
|
718 |
+
"31851 NaN \n",
|
719 |
+
"31852 NaN \n",
|
720 |
+
"31853 NaN \n",
|
721 |
"\n",
|
722 |
+
" Year Over Year % (Smoothed) (Seaonally Adjusted) Month Over Month % \\\n",
|
723 |
+
"0 NaN -0.7 \n",
|
724 |
+
"1 NaN -0.7 \n",
|
725 |
+
"2 3.2 -0.6 \n",
|
726 |
+
"3 2.7 -0.6 \n",
|
727 |
+
"4 NaN -0.7 \n",
|
728 |
+
"... ... ... \n",
|
729 |
+
"31849 NaN -0.7 \n",
|
730 |
+
"31850 NaN -0.7 \n",
|
731 |
+
"31851 NaN -1.0 \n",
|
732 |
+
"31852 NaN -0.4 \n",
|
733 |
+
"31853 NaN -0.9 \n",
|
734 |
"\n",
|
735 |
+
" Quarter Over Quarter % Year Over Year % \n",
|
736 |
+
"0 -0.9 0.6 \n",
|
737 |
+
"1 -0.9 0.6 \n",
|
738 |
+
"2 0.0 3.0 \n",
|
739 |
+
"3 0.0 2.9 \n",
|
740 |
+
"4 0.0 3.4 \n",
|
741 |
+
"... ... ... \n",
|
742 |
+
"31849 0.0 2.5 \n",
|
743 |
+
"31850 -0.9 0.6 \n",
|
744 |
+
"31851 0.0 4.5 \n",
|
745 |
+
"31852 0.9 1.2 \n",
|
746 |
+
"31853 -0.1 5.4 \n",
|
747 |
+
"\n",
|
748 |
+
"[31854 rows x 15 columns]"
|
749 |
]
|
750 |
},
|
751 |
+
"execution_count": 4,
|
752 |
"metadata": {},
|
753 |
"output_type": "execute_result"
|
754 |
}
|
755 |
],
|
756 |
"source": [
|
757 |
+
"# Adjust columns\n",
|
758 |
+
"final_df = combined_df\n",
|
759 |
+
"final_df = combined_df.drop(\"StateName\", axis=1)\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
760 |
"final_df = final_df.rename(\n",
|
761 |
" columns={\n",
|
762 |
" \"CountyName\": \"County\",\n",
|
processors/home_values.ipynb
CHANGED
@@ -2,19 +2,24 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
-
"from helpers import
|
|
|
|
|
|
|
|
|
|
|
13 |
]
|
14 |
},
|
15 |
{
|
16 |
"cell_type": "code",
|
17 |
-
"execution_count":
|
18 |
"metadata": {},
|
19 |
"outputs": [],
|
20 |
"source": [
|
@@ -27,7 +32,7 @@
|
|
27 |
},
|
28 |
{
|
29 |
"cell_type": "code",
|
30 |
-
"execution_count":
|
31 |
"metadata": {},
|
32 |
"outputs": [
|
33 |
{
|
@@ -122,15 +127,8 @@
|
|
122 |
" <th>Home Type</th>\n",
|
123 |
" <th>Date</th>\n",
|
124 |
" <th>Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)</th>\n",
|
125 |
-
" <th>Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_1</th>\n",
|
126 |
-
" <th>Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_2</th>\n",
|
127 |
" <th>Bottom Tier ZHVI (Smoothed) (Seasonally Adjusted)</th>\n",
|
128 |
-
" <th>Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_4</th>\n",
|
129 |
-
" <th>Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_5</th>\n",
|
130 |
-
" <th>Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_6</th>\n",
|
131 |
" <th>Top Tier ZHVI (Smoothed) (Seasonally Adjusted)</th>\n",
|
132 |
-
" <th>Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_8</th>\n",
|
133 |
-
" <th>Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_9</th>\n",
|
134 |
" </tr>\n",
|
135 |
" </thead>\n",
|
136 |
" <tbody>\n",
|
@@ -141,19 +139,12 @@
|
|
141 |
" <td>Alaska</td>\n",
|
142 |
" <td>state</td>\n",
|
143 |
" <td>nan</td>\n",
|
144 |
-
" <td>1-
|
145 |
" <td>all homes (SFR/condo)</td>\n",
|
146 |
" <td>2000-01-31</td>\n",
|
|
|
147 |
" <td>NaN</td>\n",
|
148 |
" <td>NaN</td>\n",
|
149 |
-
" <td>NaN</td>\n",
|
150 |
-
" <td>NaN</td>\n",
|
151 |
-
" <td>NaN</td>\n",
|
152 |
-
" <td>NaN</td>\n",
|
153 |
-
" <td>NaN</td>\n",
|
154 |
-
" <td>NaN</td>\n",
|
155 |
-
" <td>NaN</td>\n",
|
156 |
-
" <td>81310.639504</td>\n",
|
157 |
" </tr>\n",
|
158 |
" <tr>\n",
|
159 |
" <th>1</th>\n",
|
@@ -162,19 +153,12 @@
|
|
162 |
" <td>Alaska</td>\n",
|
163 |
" <td>state</td>\n",
|
164 |
" <td>nan</td>\n",
|
165 |
-
" <td>1-
|
166 |
" <td>all homes (SFR/condo)</td>\n",
|
167 |
" <td>2000-02-29</td>\n",
|
|
|
168 |
" <td>NaN</td>\n",
|
169 |
" <td>NaN</td>\n",
|
170 |
-
" <td>NaN</td>\n",
|
171 |
-
" <td>NaN</td>\n",
|
172 |
-
" <td>NaN</td>\n",
|
173 |
-
" <td>NaN</td>\n",
|
174 |
-
" <td>NaN</td>\n",
|
175 |
-
" <td>NaN</td>\n",
|
176 |
-
" <td>NaN</td>\n",
|
177 |
-
" <td>80419.761984</td>\n",
|
178 |
" </tr>\n",
|
179 |
" <tr>\n",
|
180 |
" <th>2</th>\n",
|
@@ -183,19 +167,12 @@
|
|
183 |
" <td>Alaska</td>\n",
|
184 |
" <td>state</td>\n",
|
185 |
" <td>nan</td>\n",
|
186 |
-
" <td>1-
|
187 |
" <td>all homes (SFR/condo)</td>\n",
|
188 |
" <td>2000-03-31</td>\n",
|
|
|
189 |
" <td>NaN</td>\n",
|
190 |
" <td>NaN</td>\n",
|
191 |
-
" <td>NaN</td>\n",
|
192 |
-
" <td>NaN</td>\n",
|
193 |
-
" <td>NaN</td>\n",
|
194 |
-
" <td>NaN</td>\n",
|
195 |
-
" <td>NaN</td>\n",
|
196 |
-
" <td>NaN</td>\n",
|
197 |
-
" <td>NaN</td>\n",
|
198 |
-
" <td>80480.449461</td>\n",
|
199 |
" </tr>\n",
|
200 |
" <tr>\n",
|
201 |
" <th>3</th>\n",
|
@@ -204,19 +181,12 @@
|
|
204 |
" <td>Alaska</td>\n",
|
205 |
" <td>state</td>\n",
|
206 |
" <td>nan</td>\n",
|
207 |
-
" <td>1-
|
208 |
" <td>all homes (SFR/condo)</td>\n",
|
209 |
" <td>2000-04-30</td>\n",
|
|
|
210 |
" <td>NaN</td>\n",
|
211 |
" <td>NaN</td>\n",
|
212 |
-
" <td>NaN</td>\n",
|
213 |
-
" <td>NaN</td>\n",
|
214 |
-
" <td>NaN</td>\n",
|
215 |
-
" <td>NaN</td>\n",
|
216 |
-
" <td>NaN</td>\n",
|
217 |
-
" <td>NaN</td>\n",
|
218 |
-
" <td>NaN</td>\n",
|
219 |
-
" <td>79799.206525</td>\n",
|
220 |
" </tr>\n",
|
221 |
" <tr>\n",
|
222 |
" <th>4</th>\n",
|
@@ -225,19 +195,12 @@
|
|
225 |
" <td>Alaska</td>\n",
|
226 |
" <td>state</td>\n",
|
227 |
" <td>nan</td>\n",
|
228 |
-
" <td>1-
|
229 |
" <td>all homes (SFR/condo)</td>\n",
|
230 |
" <td>2000-05-31</td>\n",
|
|
|
231 |
" <td>NaN</td>\n",
|
232 |
" <td>NaN</td>\n",
|
233 |
-
" <td>NaN</td>\n",
|
234 |
-
" <td>NaN</td>\n",
|
235 |
-
" <td>NaN</td>\n",
|
236 |
-
" <td>NaN</td>\n",
|
237 |
-
" <td>NaN</td>\n",
|
238 |
-
" <td>NaN</td>\n",
|
239 |
-
" <td>NaN</td>\n",
|
240 |
-
" <td>79666.469861</td>\n",
|
241 |
" </tr>\n",
|
242 |
" <tr>\n",
|
243 |
" <th>...</th>\n",
|
@@ -252,13 +215,6 @@
|
|
252 |
" <td>...</td>\n",
|
253 |
" <td>...</td>\n",
|
254 |
" <td>...</td>\n",
|
255 |
-
" <td>...</td>\n",
|
256 |
-
" <td>...</td>\n",
|
257 |
-
" <td>...</td>\n",
|
258 |
-
" <td>...</td>\n",
|
259 |
-
" <td>...</td>\n",
|
260 |
-
" <td>...</td>\n",
|
261 |
-
" <td>...</td>\n",
|
262 |
" </tr>\n",
|
263 |
" <tr>\n",
|
264 |
" <th>117907</th>\n",
|
@@ -270,16 +226,9 @@
|
|
270 |
" <td>All Bedrooms</td>\n",
|
271 |
" <td>condo</td>\n",
|
272 |
" <td>2023-09-30</td>\n",
|
273 |
-
" <td>NaN</td>\n",
|
274 |
-
" <td>NaN</td>\n",
|
275 |
-
" <td>NaN</td>\n",
|
276 |
-
" <td>NaN</td>\n",
|
277 |
-
" <td>NaN</td>\n",
|
278 |
" <td>486974.735908</td>\n",
|
279 |
" <td>NaN</td>\n",
|
280 |
" <td>NaN</td>\n",
|
281 |
-
" <td>NaN</td>\n",
|
282 |
-
" <td>NaN</td>\n",
|
283 |
" </tr>\n",
|
284 |
" <tr>\n",
|
285 |
" <th>117908</th>\n",
|
@@ -291,16 +240,9 @@
|
|
291 |
" <td>All Bedrooms</td>\n",
|
292 |
" <td>condo</td>\n",
|
293 |
" <td>2023-10-31</td>\n",
|
294 |
-
" <td>NaN</td>\n",
|
295 |
-
" <td>NaN</td>\n",
|
296 |
-
" <td>NaN</td>\n",
|
297 |
-
" <td>NaN</td>\n",
|
298 |
-
" <td>NaN</td>\n",
|
299 |
" <td>485847.539614</td>\n",
|
300 |
" <td>NaN</td>\n",
|
301 |
" <td>NaN</td>\n",
|
302 |
-
" <td>NaN</td>\n",
|
303 |
-
" <td>NaN</td>\n",
|
304 |
" </tr>\n",
|
305 |
" <tr>\n",
|
306 |
" <th>117909</th>\n",
|
@@ -312,16 +254,9 @@
|
|
312 |
" <td>All Bedrooms</td>\n",
|
313 |
" <td>condo</td>\n",
|
314 |
" <td>2023-11-30</td>\n",
|
315 |
-
" <td>NaN</td>\n",
|
316 |
-
" <td>NaN</td>\n",
|
317 |
-
" <td>NaN</td>\n",
|
318 |
-
" <td>NaN</td>\n",
|
319 |
-
" <td>NaN</td>\n",
|
320 |
" <td>484223.885775</td>\n",
|
321 |
" <td>NaN</td>\n",
|
322 |
" <td>NaN</td>\n",
|
323 |
-
" <td>NaN</td>\n",
|
324 |
-
" <td>NaN</td>\n",
|
325 |
" </tr>\n",
|
326 |
" <tr>\n",
|
327 |
" <th>117910</th>\n",
|
@@ -333,16 +268,9 @@
|
|
333 |
" <td>All Bedrooms</td>\n",
|
334 |
" <td>condo</td>\n",
|
335 |
" <td>2023-12-31</td>\n",
|
336 |
-
" <td>NaN</td>\n",
|
337 |
-
" <td>NaN</td>\n",
|
338 |
-
" <td>NaN</td>\n",
|
339 |
-
" <td>NaN</td>\n",
|
340 |
-
" <td>NaN</td>\n",
|
341 |
" <td>481522.403338</td>\n",
|
342 |
" <td>NaN</td>\n",
|
343 |
" <td>NaN</td>\n",
|
344 |
-
" <td>NaN</td>\n",
|
345 |
-
" <td>NaN</td>\n",
|
346 |
" </tr>\n",
|
347 |
" <tr>\n",
|
348 |
" <th>117911</th>\n",
|
@@ -354,29 +282,22 @@
|
|
354 |
" <td>All Bedrooms</td>\n",
|
355 |
" <td>condo</td>\n",
|
356 |
" <td>2024-01-31</td>\n",
|
357 |
-
" <td>NaN</td>\n",
|
358 |
-
" <td>NaN</td>\n",
|
359 |
-
" <td>NaN</td>\n",
|
360 |
-
" <td>NaN</td>\n",
|
361 |
-
" <td>NaN</td>\n",
|
362 |
" <td>481181.718200</td>\n",
|
363 |
" <td>NaN</td>\n",
|
364 |
" <td>NaN</td>\n",
|
365 |
-
" <td>NaN</td>\n",
|
366 |
-
" <td>NaN</td>\n",
|
367 |
" </tr>\n",
|
368 |
" </tbody>\n",
|
369 |
"</table>\n",
|
370 |
-
"<p>117912 rows ×
|
371 |
"</div>"
|
372 |
],
|
373 |
"text/plain": [
|
374 |
" RegionID SizeRank RegionName RegionType StateName Bedroom Count \\\n",
|
375 |
-
"0 3 48 Alaska state nan
|
376 |
-
"1 3 48 Alaska state nan
|
377 |
-
"2 3 48 Alaska state nan
|
378 |
-
"3 3 48 Alaska state nan
|
379 |
-
"4 3 48 Alaska state nan
|
380 |
"... ... ... ... ... ... ... \n",
|
381 |
"117907 62 51 Wyoming state nan All Bedrooms \n",
|
382 |
"117908 62 51 Wyoming state nan All Bedrooms \n",
|
@@ -398,43 +319,17 @@
|
|
398 |
"117911 condo 2024-01-31 \n",
|
399 |
"\n",
|
400 |
" Mid Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n",
|
401 |
-
"0
|
402 |
-
"1
|
403 |
-
"2
|
404 |
-
"3
|
405 |
-
"4
|
406 |
"... ... \n",
|
407 |
-
"117907
|
408 |
-
"117908
|
409 |
-
"117909
|
410 |
-
"117910
|
411 |
-
"117911
|
412 |
-
"\n",
|
413 |
-
" Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_1 \\\n",
|
414 |
-
"0 NaN \n",
|
415 |
-
"1 NaN \n",
|
416 |
-
"2 NaN \n",
|
417 |
-
"3 NaN \n",
|
418 |
-
"4 NaN \n",
|
419 |
-
"... ... \n",
|
420 |
-
"117907 NaN \n",
|
421 |
-
"117908 NaN \n",
|
422 |
-
"117909 NaN \n",
|
423 |
-
"117910 NaN \n",
|
424 |
-
"117911 NaN \n",
|
425 |
-
"\n",
|
426 |
-
" Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_2 \\\n",
|
427 |
-
"0 NaN \n",
|
428 |
-
"1 NaN \n",
|
429 |
-
"2 NaN \n",
|
430 |
-
"3 NaN \n",
|
431 |
-
"4 NaN \n",
|
432 |
-
"... ... \n",
|
433 |
-
"117907 NaN \n",
|
434 |
-
"117908 NaN \n",
|
435 |
-
"117909 NaN \n",
|
436 |
-
"117910 NaN \n",
|
437 |
-
"117911 NaN \n",
|
438 |
"\n",
|
439 |
" Bottom Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n",
|
440 |
"0 NaN \n",
|
@@ -449,97 +344,37 @@
|
|
449 |
"117910 NaN \n",
|
450 |
"117911 NaN \n",
|
451 |
"\n",
|
452 |
-
"
|
453 |
-
"0
|
454 |
-
"1
|
455 |
-
"2
|
456 |
-
"3
|
457 |
-
"4
|
458 |
-
"...
|
459 |
-
"117907
|
460 |
-
"117908
|
461 |
-
"117909
|
462 |
-
"117910
|
463 |
-
"117911
|
464 |
-
"\n",
|
465 |
-
" Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_5 \\\n",
|
466 |
-
"0 NaN \n",
|
467 |
-
"1 NaN \n",
|
468 |
-
"2 NaN \n",
|
469 |
-
"3 NaN \n",
|
470 |
-
"4 NaN \n",
|
471 |
-
"... ... \n",
|
472 |
-
"117907 486974.735908 \n",
|
473 |
-
"117908 485847.539614 \n",
|
474 |
-
"117909 484223.885775 \n",
|
475 |
-
"117910 481522.403338 \n",
|
476 |
-
"117911 481181.718200 \n",
|
477 |
-
"\n",
|
478 |
-
" Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_6 \\\n",
|
479 |
-
"0 NaN \n",
|
480 |
-
"1 NaN \n",
|
481 |
-
"2 NaN \n",
|
482 |
-
"3 NaN \n",
|
483 |
-
"4 NaN \n",
|
484 |
-
"... ... \n",
|
485 |
-
"117907 NaN \n",
|
486 |
-
"117908 NaN \n",
|
487 |
-
"117909 NaN \n",
|
488 |
-
"117910 NaN \n",
|
489 |
-
"117911 NaN \n",
|
490 |
-
"\n",
|
491 |
-
" Top Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n",
|
492 |
-
"0 NaN \n",
|
493 |
-
"1 NaN \n",
|
494 |
-
"2 NaN \n",
|
495 |
-
"3 NaN \n",
|
496 |
-
"4 NaN \n",
|
497 |
-
"... ... \n",
|
498 |
-
"117907 NaN \n",
|
499 |
-
"117908 NaN \n",
|
500 |
-
"117909 NaN \n",
|
501 |
-
"117910 NaN \n",
|
502 |
-
"117911 NaN \n",
|
503 |
"\n",
|
504 |
-
"
|
505 |
-
"0 NaN \n",
|
506 |
-
"1 NaN \n",
|
507 |
-
"2 NaN \n",
|
508 |
-
"3 NaN \n",
|
509 |
-
"4 NaN \n",
|
510 |
-
"... ... \n",
|
511 |
-
"117907 NaN \n",
|
512 |
-
"117908 NaN \n",
|
513 |
-
"117909 NaN \n",
|
514 |
-
"117910 NaN \n",
|
515 |
-
"117911 NaN \n",
|
516 |
-
"\n",
|
517 |
-
" Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)_9 \n",
|
518 |
-
"0 81310.639504 \n",
|
519 |
-
"1 80419.761984 \n",
|
520 |
-
"2 80480.449461 \n",
|
521 |
-
"3 79799.206525 \n",
|
522 |
-
"4 79666.469861 \n",
|
523 |
-
"... ... \n",
|
524 |
-
"117907 NaN \n",
|
525 |
-
"117908 NaN \n",
|
526 |
-
"117909 NaN \n",
|
527 |
-
"117910 NaN \n",
|
528 |
-
"117911 NaN \n",
|
529 |
-
"\n",
|
530 |
-
"[117912 rows x 18 columns]"
|
531 |
]
|
532 |
},
|
533 |
-
"execution_count":
|
534 |
"metadata": {},
|
535 |
"output_type": "execute_result"
|
536 |
}
|
537 |
],
|
538 |
"source": [
|
539 |
-
"# base cols RegionID,SizeRank,RegionName,RegionType,StateName\n",
|
540 |
-
"\n",
|
541 |
"data_frames = []\n",
|
542 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
543 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
544 |
" if filename.endswith(\".csv\"):\n",
|
545 |
" print(\"processing \" + filename)\n",
|
@@ -566,59 +401,23 @@
|
|
566 |
" continue\n",
|
567 |
"\n",
|
568 |
" if \"City\" in filename:\n",
|
569 |
-
" exclude_columns = [\n",
|
570 |
-
" \"RegionID\",\n",
|
571 |
-
" \"SizeRank\",\n",
|
572 |
-
" \"RegionName\",\n",
|
573 |
-
" \"RegionType\",\n",
|
574 |
-
" \"StateName\",\n",
|
575 |
-
" \"Bedroom Count\",\n",
|
576 |
-
" \"Home Type\",\n",
|
577 |
-
" # City Specific\n",
|
578 |
-
" \"State\",\n",
|
579 |
-
" \"Metro\",\n",
|
580 |
-
" \"CountyName\",\n",
|
581 |
-
" ]\n",
|
582 |
" elif \"Zip\" in filename:\n",
|
583 |
-
" exclude_columns = [\n",
|
584 |
-
" \"RegionID\",\n",
|
585 |
-
" \"SizeRank\",\n",
|
586 |
-
" \"RegionName\",\n",
|
587 |
-
" \"RegionType\",\n",
|
588 |
-
" \"StateName\",\n",
|
589 |
-
" \"Bedroom Count\",\n",
|
590 |
-
" \"Home Type\",\n",
|
591 |
-
" # Zip Specific\n",
|
592 |
" \"State\",\n",
|
593 |
" \"City\",\n",
|
594 |
" \"Metro\",\n",
|
595 |
" \"CountyName\",\n",
|
596 |
" ]\n",
|
597 |
" elif \"County\" in filename:\n",
|
598 |
-
" exclude_columns = [\n",
|
599 |
-
" \"RegionID\",\n",
|
600 |
-
" \"SizeRank\",\n",
|
601 |
-
" \"RegionName\",\n",
|
602 |
-
" \"RegionType\",\n",
|
603 |
-
" \"StateName\",\n",
|
604 |
-
" \"Bedroom Count\",\n",
|
605 |
-
" \"Home Type\",\n",
|
606 |
-
" # County Specific\n",
|
607 |
" \"State\",\n",
|
608 |
" \"Metro\",\n",
|
609 |
" \"StateCodeFIPS\",\n",
|
610 |
" \"MunicipalCodeFIPS\",\n",
|
611 |
" ]\n",
|
612 |
" elif \"Neighborhood\" in filename:\n",
|
613 |
-
" exclude_columns = [\n",
|
614 |
-
" \"RegionID\",\n",
|
615 |
-
" \"SizeRank\",\n",
|
616 |
-
" \"RegionName\",\n",
|
617 |
-
" \"RegionType\",\n",
|
618 |
-
" \"StateName\",\n",
|
619 |
-
" \"Bedroom Count\",\n",
|
620 |
-
" \"Home Type\",\n",
|
621 |
-
" # Neighborhood Specific\n",
|
622 |
" \"State\",\n",
|
623 |
" \"City\",\n",
|
624 |
" \"Metro\",\n",
|
@@ -626,15 +425,15 @@
|
|
626 |
" ]\n",
|
627 |
"\n",
|
628 |
" if \"_bdrmcnt_1_\" in filename:\n",
|
629 |
-
" cur_df[\"Bedroom Count\"] = \"1-
|
630 |
" elif \"_bdrmcnt_2_\" in filename:\n",
|
631 |
" cur_df[\"Bedroom Count\"] = \"2-Bedrooms\"\n",
|
632 |
" elif \"_bdrmcnt_3_\" in filename:\n",
|
633 |
" cur_df[\"Bedroom Count\"] = \"3-Bedrooms\"\n",
|
634 |
" elif \"_bdrmcnt_4_\" in filename:\n",
|
635 |
-
" cur_df[\"Bedroom Count\"] = \"4
|
636 |
" elif \"_bdrmcnt_5_\" in filename:\n",
|
637 |
-
" cur_df[\"Bedroom Count\"] = \"5
|
638 |
" else:\n",
|
639 |
" cur_df[\"Bedroom Count\"] = \"All Bedrooms\"\n",
|
640 |
"\n",
|
@@ -645,73 +444,12 @@
|
|
645 |
" elif \"_uc_condo_\" in filename:\n",
|
646 |
" cur_df[\"Home Type\"] = \"condo\"\n",
|
647 |
"\n",
|
648 |
-
" # Identify columns to pivot\n",
|
649 |
-
" columns_to_pivot = [col for col in cur_df.columns if col not in exclude_columns]\n",
|
650 |
-
"\n",
|
651 |
-
" smoothed = \"_sm_\" in filename\n",
|
652 |
-
" seasonally_adjusted = \"_sa_\" in filename\n",
|
653 |
-
"\n",
|
654 |
-
" if \"_tier_0.33_0.67_\" in filename:\n",
|
655 |
-
" col_name = \"Mid Tier ZHVI\"\n",
|
656 |
-
" if smoothed:\n",
|
657 |
-
" col_name += \" (Smoothed)\"\n",
|
658 |
-
" if seasonally_adjusted:\n",
|
659 |
-
" col_name += \" (Seasonally Adjusted)\"\n",
|
660 |
-
"\n",
|
661 |
-
" cur_df = pd.melt(\n",
|
662 |
-
" cur_df,\n",
|
663 |
-
" id_vars=exclude_columns,\n",
|
664 |
-
" value_vars=columns_to_pivot,\n",
|
665 |
-
" var_name=\"Date\",\n",
|
666 |
-
" value_name=col_name,\n",
|
667 |
-
" )\n",
|
668 |
-
" elif \"_tier_0.0_0.33_\" in filename:\n",
|
669 |
-
" col_name = \"Bottom Tier ZHVI\"\n",
|
670 |
-
" if smoothed:\n",
|
671 |
-
" col_name += \" (Smoothed)\"\n",
|
672 |
-
" if seasonally_adjusted:\n",
|
673 |
-
" col_name += \" (Seasonally Adjusted)\"\n",
|
674 |
-
"\n",
|
675 |
-
" cur_df = pd.melt(\n",
|
676 |
-
" cur_df,\n",
|
677 |
-
" id_vars=exclude_columns,\n",
|
678 |
-
" value_vars=columns_to_pivot,\n",
|
679 |
-
" var_name=\"Date\",\n",
|
680 |
-
" value_name=col_name,\n",
|
681 |
-
" )\n",
|
682 |
-
" elif \"_tier_0.67_1.0_\" in filename:\n",
|
683 |
-
" col_name = \"Top Tier ZHVI\"\n",
|
684 |
-
" if smoothed:\n",
|
685 |
-
" col_name += \" (Smoothed)\"\n",
|
686 |
-
" if seasonally_adjusted:\n",
|
687 |
-
" col_name += \" (Seasonally Adjusted)\"\n",
|
688 |
-
"\n",
|
689 |
-
" cur_df = pd.melt(\n",
|
690 |
-
" cur_df,\n",
|
691 |
-
" id_vars=exclude_columns,\n",
|
692 |
-
" value_vars=columns_to_pivot,\n",
|
693 |
-
" var_name=\"Date\",\n",
|
694 |
-
" value_name=col_name,\n",
|
695 |
-
" )\n",
|
696 |
-
" else:\n",
|
697 |
-
" col_name = \"ZHVI\"\n",
|
698 |
-
" if smoothed:\n",
|
699 |
-
" col_name += \" (Smoothed)\"\n",
|
700 |
-
" if seasonally_adjusted:\n",
|
701 |
-
" col_name += \" (Seasonally Adjusted)\"\n",
|
702 |
-
"\n",
|
703 |
-
" cur_df = pd.melt(\n",
|
704 |
-
" cur_df,\n",
|
705 |
-
" id_vars=exclude_columns,\n",
|
706 |
-
" value_vars=columns_to_pivot,\n",
|
707 |
-
" var_name=\"Date\",\n",
|
708 |
-
" value_name=col_name,\n",
|
709 |
-
" )\n",
|
710 |
-
"\n",
|
711 |
" cur_df[\"StateName\"] = cur_df[\"StateName\"].astype(str)\n",
|
712 |
" cur_df[\"RegionName\"] = cur_df[\"RegionName\"].astype(str)\n",
|
713 |
"\n",
|
714 |
-
" data_frames
|
|
|
|
|
715 |
"\n",
|
716 |
"\n",
|
717 |
"combined_df = get_combined_df(\n",
|
@@ -727,323 +465,8 @@
|
|
727 |
" \"Date\",\n",
|
728 |
" ],\n",
|
729 |
")\n",
|
730 |
-
"combined_df"
|
731 |
-
]
|
732 |
-
},
|
733 |
-
{
|
734 |
-
"cell_type": "code",
|
735 |
-
"execution_count": 4,
|
736 |
-
"metadata": {},
|
737 |
-
"outputs": [
|
738 |
-
{
|
739 |
-
"data": {
|
740 |
-
"text/html": [
|
741 |
-
"<div>\n",
|
742 |
-
"<style scoped>\n",
|
743 |
-
" .dataframe tbody tr th:only-of-type {\n",
|
744 |
-
" vertical-align: middle;\n",
|
745 |
-
" }\n",
|
746 |
-
"\n",
|
747 |
-
" .dataframe tbody tr th {\n",
|
748 |
-
" vertical-align: top;\n",
|
749 |
-
" }\n",
|
750 |
-
"\n",
|
751 |
-
" .dataframe thead th {\n",
|
752 |
-
" text-align: right;\n",
|
753 |
-
" }\n",
|
754 |
-
"</style>\n",
|
755 |
-
"<table border=\"1\" class=\"dataframe\">\n",
|
756 |
-
" <thead>\n",
|
757 |
-
" <tr style=\"text-align: right;\">\n",
|
758 |
-
" <th></th>\n",
|
759 |
-
" <th>RegionID</th>\n",
|
760 |
-
" <th>SizeRank</th>\n",
|
761 |
-
" <th>RegionName</th>\n",
|
762 |
-
" <th>RegionType</th>\n",
|
763 |
-
" <th>StateName</th>\n",
|
764 |
-
" <th>Bedroom Count</th>\n",
|
765 |
-
" <th>Home Type</th>\n",
|
766 |
-
" <th>Date</th>\n",
|
767 |
-
" <th>Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)</th>\n",
|
768 |
-
" <th>Bottom Tier ZHVI (Smoothed) (Seasonally Adjusted)</th>\n",
|
769 |
-
" <th>Top Tier ZHVI (Smoothed) (Seasonally Adjusted)</th>\n",
|
770 |
-
" <th>ZHVI</th>\n",
|
771 |
-
" <th>Mid Tier ZHVI</th>\n",
|
772 |
-
" </tr>\n",
|
773 |
-
" </thead>\n",
|
774 |
-
" <tbody>\n",
|
775 |
-
" <tr>\n",
|
776 |
-
" <th>0</th>\n",
|
777 |
-
" <td>3</td>\n",
|
778 |
-
" <td>48</td>\n",
|
779 |
-
" <td>Alaska</td>\n",
|
780 |
-
" <td>state</td>\n",
|
781 |
-
" <td>nan</td>\n",
|
782 |
-
" <td>1-Bedrooms</td>\n",
|
783 |
-
" <td>all homes (SFR/condo)</td>\n",
|
784 |
-
" <td>2000-01-31</td>\n",
|
785 |
-
" <td>NaN</td>\n",
|
786 |
-
" <td>NaN</td>\n",
|
787 |
-
" <td>NaN</td>\n",
|
788 |
-
" <td>81310.639504</td>\n",
|
789 |
-
" <td>81310.639504</td>\n",
|
790 |
-
" </tr>\n",
|
791 |
-
" <tr>\n",
|
792 |
-
" <th>1</th>\n",
|
793 |
-
" <td>3</td>\n",
|
794 |
-
" <td>48</td>\n",
|
795 |
-
" <td>Alaska</td>\n",
|
796 |
-
" <td>state</td>\n",
|
797 |
-
" <td>nan</td>\n",
|
798 |
-
" <td>1-Bedrooms</td>\n",
|
799 |
-
" <td>all homes (SFR/condo)</td>\n",
|
800 |
-
" <td>2000-02-29</td>\n",
|
801 |
-
" <td>NaN</td>\n",
|
802 |
-
" <td>NaN</td>\n",
|
803 |
-
" <td>NaN</td>\n",
|
804 |
-
" <td>80419.761984</td>\n",
|
805 |
-
" <td>80419.761984</td>\n",
|
806 |
-
" </tr>\n",
|
807 |
-
" <tr>\n",
|
808 |
-
" <th>2</th>\n",
|
809 |
-
" <td>3</td>\n",
|
810 |
-
" <td>48</td>\n",
|
811 |
-
" <td>Alaska</td>\n",
|
812 |
-
" <td>state</td>\n",
|
813 |
-
" <td>nan</td>\n",
|
814 |
-
" <td>1-Bedrooms</td>\n",
|
815 |
-
" <td>all homes (SFR/condo)</td>\n",
|
816 |
-
" <td>2000-03-31</td>\n",
|
817 |
-
" <td>NaN</td>\n",
|
818 |
-
" <td>NaN</td>\n",
|
819 |
-
" <td>NaN</td>\n",
|
820 |
-
" <td>80480.449461</td>\n",
|
821 |
-
" <td>80480.449461</td>\n",
|
822 |
-
" </tr>\n",
|
823 |
-
" <tr>\n",
|
824 |
-
" <th>3</th>\n",
|
825 |
-
" <td>3</td>\n",
|
826 |
-
" <td>48</td>\n",
|
827 |
-
" <td>Alaska</td>\n",
|
828 |
-
" <td>state</td>\n",
|
829 |
-
" <td>nan</td>\n",
|
830 |
-
" <td>1-Bedrooms</td>\n",
|
831 |
-
" <td>all homes (SFR/condo)</td>\n",
|
832 |
-
" <td>2000-04-30</td>\n",
|
833 |
-
" <td>NaN</td>\n",
|
834 |
-
" <td>NaN</td>\n",
|
835 |
-
" <td>NaN</td>\n",
|
836 |
-
" <td>79799.206525</td>\n",
|
837 |
-
" <td>79799.206525</td>\n",
|
838 |
-
" </tr>\n",
|
839 |
-
" <tr>\n",
|
840 |
-
" <th>4</th>\n",
|
841 |
-
" <td>3</td>\n",
|
842 |
-
" <td>48</td>\n",
|
843 |
-
" <td>Alaska</td>\n",
|
844 |
-
" <td>state</td>\n",
|
845 |
-
" <td>nan</td>\n",
|
846 |
-
" <td>1-Bedrooms</td>\n",
|
847 |
-
" <td>all homes (SFR/condo)</td>\n",
|
848 |
-
" <td>2000-05-31</td>\n",
|
849 |
-
" <td>NaN</td>\n",
|
850 |
-
" <td>NaN</td>\n",
|
851 |
-
" <td>NaN</td>\n",
|
852 |
-
" <td>79666.469861</td>\n",
|
853 |
-
" <td>79666.469861</td>\n",
|
854 |
-
" </tr>\n",
|
855 |
-
" <tr>\n",
|
856 |
-
" <th>...</th>\n",
|
857 |
-
" <td>...</td>\n",
|
858 |
-
" <td>...</td>\n",
|
859 |
-
" <td>...</td>\n",
|
860 |
-
" <td>...</td>\n",
|
861 |
-
" <td>...</td>\n",
|
862 |
-
" <td>...</td>\n",
|
863 |
-
" <td>...</td>\n",
|
864 |
-
" <td>...</td>\n",
|
865 |
-
" <td>...</td>\n",
|
866 |
-
" <td>...</td>\n",
|
867 |
-
" <td>...</td>\n",
|
868 |
-
" <td>...</td>\n",
|
869 |
-
" <td>...</td>\n",
|
870 |
-
" </tr>\n",
|
871 |
-
" <tr>\n",
|
872 |
-
" <th>117907</th>\n",
|
873 |
-
" <td>62</td>\n",
|
874 |
-
" <td>51</td>\n",
|
875 |
-
" <td>Wyoming</td>\n",
|
876 |
-
" <td>state</td>\n",
|
877 |
-
" <td>nan</td>\n",
|
878 |
-
" <td>All Bedrooms</td>\n",
|
879 |
-
" <td>condo</td>\n",
|
880 |
-
" <td>2023-09-30</td>\n",
|
881 |
-
" <td>NaN</td>\n",
|
882 |
-
" <td>NaN</td>\n",
|
883 |
-
" <td>NaN</td>\n",
|
884 |
-
" <td>486974.735908</td>\n",
|
885 |
-
" <td>486974.735908</td>\n",
|
886 |
-
" </tr>\n",
|
887 |
-
" <tr>\n",
|
888 |
-
" <th>117908</th>\n",
|
889 |
-
" <td>62</td>\n",
|
890 |
-
" <td>51</td>\n",
|
891 |
-
" <td>Wyoming</td>\n",
|
892 |
-
" <td>state</td>\n",
|
893 |
-
" <td>nan</td>\n",
|
894 |
-
" <td>All Bedrooms</td>\n",
|
895 |
-
" <td>condo</td>\n",
|
896 |
-
" <td>2023-10-31</td>\n",
|
897 |
-
" <td>NaN</td>\n",
|
898 |
-
" <td>NaN</td>\n",
|
899 |
-
" <td>NaN</td>\n",
|
900 |
-
" <td>485847.539614</td>\n",
|
901 |
-
" <td>485847.539614</td>\n",
|
902 |
-
" </tr>\n",
|
903 |
-
" <tr>\n",
|
904 |
-
" <th>117909</th>\n",
|
905 |
-
" <td>62</td>\n",
|
906 |
-
" <td>51</td>\n",
|
907 |
-
" <td>Wyoming</td>\n",
|
908 |
-
" <td>state</td>\n",
|
909 |
-
" <td>nan</td>\n",
|
910 |
-
" <td>All Bedrooms</td>\n",
|
911 |
-
" <td>condo</td>\n",
|
912 |
-
" <td>2023-11-30</td>\n",
|
913 |
-
" <td>NaN</td>\n",
|
914 |
-
" <td>NaN</td>\n",
|
915 |
-
" <td>NaN</td>\n",
|
916 |
-
" <td>484223.885775</td>\n",
|
917 |
-
" <td>484223.885775</td>\n",
|
918 |
-
" </tr>\n",
|
919 |
-
" <tr>\n",
|
920 |
-
" <th>117910</th>\n",
|
921 |
-
" <td>62</td>\n",
|
922 |
-
" <td>51</td>\n",
|
923 |
-
" <td>Wyoming</td>\n",
|
924 |
-
" <td>state</td>\n",
|
925 |
-
" <td>nan</td>\n",
|
926 |
-
" <td>All Bedrooms</td>\n",
|
927 |
-
" <td>condo</td>\n",
|
928 |
-
" <td>2023-12-31</td>\n",
|
929 |
-
" <td>NaN</td>\n",
|
930 |
-
" <td>NaN</td>\n",
|
931 |
-
" <td>NaN</td>\n",
|
932 |
-
" <td>481522.403338</td>\n",
|
933 |
-
" <td>481522.403338</td>\n",
|
934 |
-
" </tr>\n",
|
935 |
-
" <tr>\n",
|
936 |
-
" <th>117911</th>\n",
|
937 |
-
" <td>62</td>\n",
|
938 |
-
" <td>51</td>\n",
|
939 |
-
" <td>Wyoming</td>\n",
|
940 |
-
" <td>state</td>\n",
|
941 |
-
" <td>nan</td>\n",
|
942 |
-
" <td>All Bedrooms</td>\n",
|
943 |
-
" <td>condo</td>\n",
|
944 |
-
" <td>2024-01-31</td>\n",
|
945 |
-
" <td>NaN</td>\n",
|
946 |
-
" <td>NaN</td>\n",
|
947 |
-
" <td>NaN</td>\n",
|
948 |
-
" <td>481181.718200</td>\n",
|
949 |
-
" <td>481181.718200</td>\n",
|
950 |
-
" </tr>\n",
|
951 |
-
" </tbody>\n",
|
952 |
-
"</table>\n",
|
953 |
-
"<p>117912 rows × 13 columns</p>\n",
|
954 |
-
"</div>"
|
955 |
-
],
|
956 |
-
"text/plain": [
|
957 |
-
" RegionID SizeRank RegionName RegionType StateName Bedroom Count \\\n",
|
958 |
-
"0 3 48 Alaska state nan 1-Bedrooms \n",
|
959 |
-
"1 3 48 Alaska state nan 1-Bedrooms \n",
|
960 |
-
"2 3 48 Alaska state nan 1-Bedrooms \n",
|
961 |
-
"3 3 48 Alaska state nan 1-Bedrooms \n",
|
962 |
-
"4 3 48 Alaska state nan 1-Bedrooms \n",
|
963 |
-
"... ... ... ... ... ... ... \n",
|
964 |
-
"117907 62 51 Wyoming state nan All Bedrooms \n",
|
965 |
-
"117908 62 51 Wyoming state nan All Bedrooms \n",
|
966 |
-
"117909 62 51 Wyoming state nan All Bedrooms \n",
|
967 |
-
"117910 62 51 Wyoming state nan All Bedrooms \n",
|
968 |
-
"117911 62 51 Wyoming state nan All Bedrooms \n",
|
969 |
-
"\n",
|
970 |
-
" Home Type Date \\\n",
|
971 |
-
"0 all homes (SFR/condo) 2000-01-31 \n",
|
972 |
-
"1 all homes (SFR/condo) 2000-02-29 \n",
|
973 |
-
"2 all homes (SFR/condo) 2000-03-31 \n",
|
974 |
-
"3 all homes (SFR/condo) 2000-04-30 \n",
|
975 |
-
"4 all homes (SFR/condo) 2000-05-31 \n",
|
976 |
-
"... ... ... \n",
|
977 |
-
"117907 condo 2023-09-30 \n",
|
978 |
-
"117908 condo 2023-10-31 \n",
|
979 |
-
"117909 condo 2023-11-30 \n",
|
980 |
-
"117910 condo 2023-12-31 \n",
|
981 |
-
"117911 condo 2024-01-31 \n",
|
982 |
-
"\n",
|
983 |
-
" Mid Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n",
|
984 |
-
"0 NaN \n",
|
985 |
-
"1 NaN \n",
|
986 |
-
"2 NaN \n",
|
987 |
-
"3 NaN \n",
|
988 |
-
"4 NaN \n",
|
989 |
-
"... ... \n",
|
990 |
-
"117907 NaN \n",
|
991 |
-
"117908 NaN \n",
|
992 |
-
"117909 NaN \n",
|
993 |
-
"117910 NaN \n",
|
994 |
-
"117911 NaN \n",
|
995 |
-
"\n",
|
996 |
-
" Bottom Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n",
|
997 |
-
"0 NaN \n",
|
998 |
-
"1 NaN \n",
|
999 |
-
"2 NaN \n",
|
1000 |
-
"3 NaN \n",
|
1001 |
-
"4 NaN \n",
|
1002 |
-
"... ... \n",
|
1003 |
-
"117907 NaN \n",
|
1004 |
-
"117908 NaN \n",
|
1005 |
-
"117909 NaN \n",
|
1006 |
-
"117910 NaN \n",
|
1007 |
-
"117911 NaN \n",
|
1008 |
-
"\n",
|
1009 |
-
" Top Tier ZHVI (Smoothed) (Seasonally Adjusted) ZHVI \\\n",
|
1010 |
-
"0 NaN 81310.639504 \n",
|
1011 |
-
"1 NaN 80419.761984 \n",
|
1012 |
-
"2 NaN 80480.449461 \n",
|
1013 |
-
"3 NaN 79799.206525 \n",
|
1014 |
-
"4 NaN 79666.469861 \n",
|
1015 |
-
"... ... ... \n",
|
1016 |
-
"117907 NaN 486974.735908 \n",
|
1017 |
-
"117908 NaN 485847.539614 \n",
|
1018 |
-
"117909 NaN 484223.885775 \n",
|
1019 |
-
"117910 NaN 481522.403338 \n",
|
1020 |
-
"117911 NaN 481181.718200 \n",
|
1021 |
-
"\n",
|
1022 |
-
" Mid Tier ZHVI \n",
|
1023 |
-
"0 81310.639504 \n",
|
1024 |
-
"1 80419.761984 \n",
|
1025 |
-
"2 80480.449461 \n",
|
1026 |
-
"3 79799.206525 \n",
|
1027 |
-
"4 79666.469861 \n",
|
1028 |
-
"... ... \n",
|
1029 |
-
"117907 486974.735908 \n",
|
1030 |
-
"117908 485847.539614 \n",
|
1031 |
-
"117909 484223.885775 \n",
|
1032 |
-
"117910 481522.403338 \n",
|
1033 |
-
"117911 481181.718200 \n",
|
1034 |
-
"\n",
|
1035 |
-
"[117912 rows x 13 columns]"
|
1036 |
-
]
|
1037 |
-
},
|
1038 |
-
"execution_count": 4,
|
1039 |
-
"metadata": {},
|
1040 |
-
"output_type": "execute_result"
|
1041 |
-
}
|
1042 |
-
],
|
1043 |
-
"source": [
|
1044 |
-
"columns_to_coalesce = [\"ZHVI\", \"Mid Tier ZHVI\", \"Bottom Tier ZHVI\", \"Top Tier ZHVI\"]\n",
|
1045 |
"\n",
|
1046 |
-
"combined_df = coalesce_columns(combined_df
|
1047 |
"\n",
|
1048 |
"combined_df"
|
1049 |
]
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
+
"from helpers import (\n",
|
13 |
+
" get_combined_df,\n",
|
14 |
+
" coalesce_columns,\n",
|
15 |
+
" save_final_df_as_jsonl,\n",
|
16 |
+
" handle_slug_column_mappings,\n",
|
17 |
+
")"
|
18 |
]
|
19 |
},
|
20 |
{
|
21 |
"cell_type": "code",
|
22 |
+
"execution_count": 2,
|
23 |
"metadata": {},
|
24 |
"outputs": [],
|
25 |
"source": [
|
|
|
32 |
},
|
33 |
{
|
34 |
"cell_type": "code",
|
35 |
+
"execution_count": 5,
|
36 |
"metadata": {},
|
37 |
"outputs": [
|
38 |
{
|
|
|
127 |
" <th>Home Type</th>\n",
|
128 |
" <th>Date</th>\n",
|
129 |
" <th>Mid Tier ZHVI (Smoothed) (Seasonally Adjusted)</th>\n",
|
|
|
|
|
130 |
" <th>Bottom Tier ZHVI (Smoothed) (Seasonally Adjusted)</th>\n",
|
|
|
|
|
|
|
131 |
" <th>Top Tier ZHVI (Smoothed) (Seasonally Adjusted)</th>\n",
|
|
|
|
|
132 |
" </tr>\n",
|
133 |
" </thead>\n",
|
134 |
" <tbody>\n",
|
|
|
139 |
" <td>Alaska</td>\n",
|
140 |
" <td>state</td>\n",
|
141 |
" <td>nan</td>\n",
|
142 |
+
" <td>1-Bedroom</td>\n",
|
143 |
" <td>all homes (SFR/condo)</td>\n",
|
144 |
" <td>2000-01-31</td>\n",
|
145 |
+
" <td>81310.639504</td>\n",
|
146 |
" <td>NaN</td>\n",
|
147 |
" <td>NaN</td>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
" </tr>\n",
|
149 |
" <tr>\n",
|
150 |
" <th>1</th>\n",
|
|
|
153 |
" <td>Alaska</td>\n",
|
154 |
" <td>state</td>\n",
|
155 |
" <td>nan</td>\n",
|
156 |
+
" <td>1-Bedroom</td>\n",
|
157 |
" <td>all homes (SFR/condo)</td>\n",
|
158 |
" <td>2000-02-29</td>\n",
|
159 |
+
" <td>80419.761984</td>\n",
|
160 |
" <td>NaN</td>\n",
|
161 |
" <td>NaN</td>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
" </tr>\n",
|
163 |
" <tr>\n",
|
164 |
" <th>2</th>\n",
|
|
|
167 |
" <td>Alaska</td>\n",
|
168 |
" <td>state</td>\n",
|
169 |
" <td>nan</td>\n",
|
170 |
+
" <td>1-Bedroom</td>\n",
|
171 |
" <td>all homes (SFR/condo)</td>\n",
|
172 |
" <td>2000-03-31</td>\n",
|
173 |
+
" <td>80480.449461</td>\n",
|
174 |
" <td>NaN</td>\n",
|
175 |
" <td>NaN</td>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
" </tr>\n",
|
177 |
" <tr>\n",
|
178 |
" <th>3</th>\n",
|
|
|
181 |
" <td>Alaska</td>\n",
|
182 |
" <td>state</td>\n",
|
183 |
" <td>nan</td>\n",
|
184 |
+
" <td>1-Bedroom</td>\n",
|
185 |
" <td>all homes (SFR/condo)</td>\n",
|
186 |
" <td>2000-04-30</td>\n",
|
187 |
+
" <td>79799.206525</td>\n",
|
188 |
" <td>NaN</td>\n",
|
189 |
" <td>NaN</td>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
" </tr>\n",
|
191 |
" <tr>\n",
|
192 |
" <th>4</th>\n",
|
|
|
195 |
" <td>Alaska</td>\n",
|
196 |
" <td>state</td>\n",
|
197 |
" <td>nan</td>\n",
|
198 |
+
" <td>1-Bedroom</td>\n",
|
199 |
" <td>all homes (SFR/condo)</td>\n",
|
200 |
" <td>2000-05-31</td>\n",
|
201 |
+
" <td>79666.469861</td>\n",
|
202 |
" <td>NaN</td>\n",
|
203 |
" <td>NaN</td>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
" </tr>\n",
|
205 |
" <tr>\n",
|
206 |
" <th>...</th>\n",
|
|
|
215 |
" <td>...</td>\n",
|
216 |
" <td>...</td>\n",
|
217 |
" <td>...</td>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
" </tr>\n",
|
219 |
" <tr>\n",
|
220 |
" <th>117907</th>\n",
|
|
|
226 |
" <td>All Bedrooms</td>\n",
|
227 |
" <td>condo</td>\n",
|
228 |
" <td>2023-09-30</td>\n",
|
|
|
|
|
|
|
|
|
|
|
229 |
" <td>486974.735908</td>\n",
|
230 |
" <td>NaN</td>\n",
|
231 |
" <td>NaN</td>\n",
|
|
|
|
|
232 |
" </tr>\n",
|
233 |
" <tr>\n",
|
234 |
" <th>117908</th>\n",
|
|
|
240 |
" <td>All Bedrooms</td>\n",
|
241 |
" <td>condo</td>\n",
|
242 |
" <td>2023-10-31</td>\n",
|
|
|
|
|
|
|
|
|
|
|
243 |
" <td>485847.539614</td>\n",
|
244 |
" <td>NaN</td>\n",
|
245 |
" <td>NaN</td>\n",
|
|
|
|
|
246 |
" </tr>\n",
|
247 |
" <tr>\n",
|
248 |
" <th>117909</th>\n",
|
|
|
254 |
" <td>All Bedrooms</td>\n",
|
255 |
" <td>condo</td>\n",
|
256 |
" <td>2023-11-30</td>\n",
|
|
|
|
|
|
|
|
|
|
|
257 |
" <td>484223.885775</td>\n",
|
258 |
" <td>NaN</td>\n",
|
259 |
" <td>NaN</td>\n",
|
|
|
|
|
260 |
" </tr>\n",
|
261 |
" <tr>\n",
|
262 |
" <th>117910</th>\n",
|
|
|
268 |
" <td>All Bedrooms</td>\n",
|
269 |
" <td>condo</td>\n",
|
270 |
" <td>2023-12-31</td>\n",
|
|
|
|
|
|
|
|
|
|
|
271 |
" <td>481522.403338</td>\n",
|
272 |
" <td>NaN</td>\n",
|
273 |
" <td>NaN</td>\n",
|
|
|
|
|
274 |
" </tr>\n",
|
275 |
" <tr>\n",
|
276 |
" <th>117911</th>\n",
|
|
|
282 |
" <td>All Bedrooms</td>\n",
|
283 |
" <td>condo</td>\n",
|
284 |
" <td>2024-01-31</td>\n",
|
|
|
|
|
|
|
|
|
|
|
285 |
" <td>481181.718200</td>\n",
|
286 |
" <td>NaN</td>\n",
|
287 |
" <td>NaN</td>\n",
|
|
|
|
|
288 |
" </tr>\n",
|
289 |
" </tbody>\n",
|
290 |
"</table>\n",
|
291 |
+
"<p>117912 rows × 11 columns</p>\n",
|
292 |
"</div>"
|
293 |
],
|
294 |
"text/plain": [
|
295 |
" RegionID SizeRank RegionName RegionType StateName Bedroom Count \\\n",
|
296 |
+
"0 3 48 Alaska state nan 1-Bedroom \n",
|
297 |
+
"1 3 48 Alaska state nan 1-Bedroom \n",
|
298 |
+
"2 3 48 Alaska state nan 1-Bedroom \n",
|
299 |
+
"3 3 48 Alaska state nan 1-Bedroom \n",
|
300 |
+
"4 3 48 Alaska state nan 1-Bedroom \n",
|
301 |
"... ... ... ... ... ... ... \n",
|
302 |
"117907 62 51 Wyoming state nan All Bedrooms \n",
|
303 |
"117908 62 51 Wyoming state nan All Bedrooms \n",
|
|
|
319 |
"117911 condo 2024-01-31 \n",
|
320 |
"\n",
|
321 |
" Mid Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n",
|
322 |
+
"0 81310.639504 \n",
|
323 |
+
"1 80419.761984 \n",
|
324 |
+
"2 80480.449461 \n",
|
325 |
+
"3 79799.206525 \n",
|
326 |
+
"4 79666.469861 \n",
|
327 |
"... ... \n",
|
328 |
+
"117907 486974.735908 \n",
|
329 |
+
"117908 485847.539614 \n",
|
330 |
+
"117909 484223.885775 \n",
|
331 |
+
"117910 481522.403338 \n",
|
332 |
+
"117911 481181.718200 \n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
333 |
"\n",
|
334 |
" Bottom Tier ZHVI (Smoothed) (Seasonally Adjusted) \\\n",
|
335 |
"0 NaN \n",
|
|
|
344 |
"117910 NaN \n",
|
345 |
"117911 NaN \n",
|
346 |
"\n",
|
347 |
+
" Top Tier ZHVI (Smoothed) (Seasonally Adjusted) \n",
|
348 |
+
"0 NaN \n",
|
349 |
+
"1 NaN \n",
|
350 |
+
"2 NaN \n",
|
351 |
+
"3 NaN \n",
|
352 |
+
"4 NaN \n",
|
353 |
+
"... ... \n",
|
354 |
+
"117907 NaN \n",
|
355 |
+
"117908 NaN \n",
|
356 |
+
"117909 NaN \n",
|
357 |
+
"117910 NaN \n",
|
358 |
+
"117911 NaN \n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
359 |
"\n",
|
360 |
+
"[117912 rows x 11 columns]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
]
|
362 |
},
|
363 |
+
"execution_count": 5,
|
364 |
"metadata": {},
|
365 |
"output_type": "execute_result"
|
366 |
}
|
367 |
],
|
368 |
"source": [
|
|
|
|
|
369 |
"data_frames = []\n",
|
370 |
"\n",
|
371 |
+
"slug_column_mappings = {\n",
|
372 |
+
" \"_tier_0.0_0.33_\": \"Bottom Tier ZHVI\",\n",
|
373 |
+
" \"_tier_0.33_0.67_\": \"Mid Tier ZHVI\",\n",
|
374 |
+
" \"_tier_0.67_1.0_\": \"Top Tier ZHVI\",\n",
|
375 |
+
" \"\": \"ZHVI\",\n",
|
376 |
+
"}\n",
|
377 |
+
"\n",
|
378 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
379 |
" if filename.endswith(\".csv\"):\n",
|
380 |
" print(\"processing \" + filename)\n",
|
|
|
401 |
" continue\n",
|
402 |
"\n",
|
403 |
" if \"City\" in filename:\n",
|
404 |
+
" exclude_columns = exclude_columns + [\"State\", \"Metro\", \"CountyName\"]\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
" elif \"Zip\" in filename:\n",
|
406 |
+
" exclude_columns = exclude_columns + [\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
407 |
" \"State\",\n",
|
408 |
" \"City\",\n",
|
409 |
" \"Metro\",\n",
|
410 |
" \"CountyName\",\n",
|
411 |
" ]\n",
|
412 |
" elif \"County\" in filename:\n",
|
413 |
+
" exclude_columns = exclude_columns + [\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
414 |
" \"State\",\n",
|
415 |
" \"Metro\",\n",
|
416 |
" \"StateCodeFIPS\",\n",
|
417 |
" \"MunicipalCodeFIPS\",\n",
|
418 |
" ]\n",
|
419 |
" elif \"Neighborhood\" in filename:\n",
|
420 |
+
" exclude_columns = exclude_columns + [\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
421 |
" \"State\",\n",
|
422 |
" \"City\",\n",
|
423 |
" \"Metro\",\n",
|
|
|
425 |
" ]\n",
|
426 |
"\n",
|
427 |
" if \"_bdrmcnt_1_\" in filename:\n",
|
428 |
+
" cur_df[\"Bedroom Count\"] = \"1-Bedroom\"\n",
|
429 |
" elif \"_bdrmcnt_2_\" in filename:\n",
|
430 |
" cur_df[\"Bedroom Count\"] = \"2-Bedrooms\"\n",
|
431 |
" elif \"_bdrmcnt_3_\" in filename:\n",
|
432 |
" cur_df[\"Bedroom Count\"] = \"3-Bedrooms\"\n",
|
433 |
" elif \"_bdrmcnt_4_\" in filename:\n",
|
434 |
+
" cur_df[\"Bedroom Count\"] = \"4-Bedrooms\"\n",
|
435 |
" elif \"_bdrmcnt_5_\" in filename:\n",
|
436 |
+
" cur_df[\"Bedroom Count\"] = \"5+-Bedrooms\"\n",
|
437 |
" else:\n",
|
438 |
" cur_df[\"Bedroom Count\"] = \"All Bedrooms\"\n",
|
439 |
"\n",
|
|
|
444 |
" elif \"_uc_condo_\" in filename:\n",
|
445 |
" cur_df[\"Home Type\"] = \"condo\"\n",
|
446 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
" cur_df[\"StateName\"] = cur_df[\"StateName\"].astype(str)\n",
|
448 |
" cur_df[\"RegionName\"] = cur_df[\"RegionName\"].astype(str)\n",
|
449 |
"\n",
|
450 |
+
" data_frames = handle_slug_column_mappings(\n",
|
451 |
+
" data_frames, slug_column_mappings, exclude_columns, filename, cur_df\n",
|
452 |
+
" )\n",
|
453 |
"\n",
|
454 |
"\n",
|
455 |
"combined_df = get_combined_df(\n",
|
|
|
465 |
" \"Date\",\n",
|
466 |
" ],\n",
|
467 |
")\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
468 |
"\n",
|
469 |
+
"combined_df = coalesce_columns(combined_df)\n",
|
470 |
"\n",
|
471 |
"combined_df"
|
472 |
]
|
processors/new_construction.ipynb
CHANGED
@@ -9,7 +9,12 @@
|
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
-
"from helpers import
|
|
|
|
|
|
|
|
|
|
|
13 |
]
|
14 |
},
|
15 |
{
|
@@ -263,8 +268,6 @@
|
|
263 |
}
|
264 |
],
|
265 |
"source": [
|
266 |
-
"# base cols RegionID,SizeRank,RegionName,RegionType,StateName\n",
|
267 |
-
"\n",
|
268 |
"exclude_columns = [\n",
|
269 |
" \"RegionID\",\n",
|
270 |
" \"SizeRank\",\n",
|
@@ -274,6 +277,12 @@
|
|
274 |
" \"Home Type\",\n",
|
275 |
"]\n",
|
276 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
"data_frames = []\n",
|
278 |
"\n",
|
279 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
@@ -288,38 +297,9 @@
|
|
288 |
" elif \"condo\" in filename:\n",
|
289 |
" cur_df[\"Home Type\"] = \"condo/co-op only\"\n",
|
290 |
"\n",
|
291 |
-
"
|
292 |
-
"
|
293 |
-
"\n",
|
294 |
-
" if \"median_sale_price_per_sqft\" in filename:\n",
|
295 |
-
" cur_df = pd.melt(\n",
|
296 |
-
" cur_df,\n",
|
297 |
-
" id_vars=exclude_columns,\n",
|
298 |
-
" value_vars=columns_to_pivot,\n",
|
299 |
-
" var_name=\"Date\",\n",
|
300 |
-
" value_name=\"Median Sale Price per Sqft\",\n",
|
301 |
-
" )\n",
|
302 |
-
" data_frames.append(cur_df)\n",
|
303 |
-
"\n",
|
304 |
-
" elif \"median_sale_price\" in filename:\n",
|
305 |
-
" cur_df = pd.melt(\n",
|
306 |
-
" cur_df,\n",
|
307 |
-
" id_vars=exclude_columns,\n",
|
308 |
-
" value_vars=columns_to_pivot,\n",
|
309 |
-
" var_name=\"Date\",\n",
|
310 |
-
" value_name=\"Median Sale Price\",\n",
|
311 |
-
" )\n",
|
312 |
-
" data_frames.append(cur_df)\n",
|
313 |
-
"\n",
|
314 |
-
" elif \"sales_count\" in filename:\n",
|
315 |
-
" cur_df = pd.melt(\n",
|
316 |
-
" cur_df,\n",
|
317 |
-
" id_vars=exclude_columns,\n",
|
318 |
-
" value_vars=columns_to_pivot,\n",
|
319 |
-
" var_name=\"Date\",\n",
|
320 |
-
" value_name=\"Sales Count\",\n",
|
321 |
-
" )\n",
|
322 |
-
" data_frames.append(cur_df)\n",
|
323 |
"\n",
|
324 |
"\n",
|
325 |
"combined_df = get_combined_df(\n",
|
@@ -334,10 +314,8 @@
|
|
334 |
" \"Date\",\n",
|
335 |
" ],\n",
|
336 |
")\n",
|
337 |
-
"# iterate over rows of combined df and coalesce column values across columns that start with \"Median Sale Price\"\n",
|
338 |
-
"columns_to_coalesce = [\"Sales Count\", \"Median Sale Price\", \"Median Sale Price per Sqft\"]\n",
|
339 |
"\n",
|
340 |
-
"combined_df = coalesce_columns(combined_df
|
341 |
"\n",
|
342 |
"combined_df"
|
343 |
]
|
|
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
+
"from helpers import (\n",
|
13 |
+
" get_combined_df,\n",
|
14 |
+
" coalesce_columns,\n",
|
15 |
+
" save_final_df_as_jsonl,\n",
|
16 |
+
" handle_slug_column_mappings,\n",
|
17 |
+
")"
|
18 |
]
|
19 |
},
|
20 |
{
|
|
|
268 |
}
|
269 |
],
|
270 |
"source": [
|
|
|
|
|
271 |
"exclude_columns = [\n",
|
272 |
" \"RegionID\",\n",
|
273 |
" \"SizeRank\",\n",
|
|
|
277 |
" \"Home Type\",\n",
|
278 |
"]\n",
|
279 |
"\n",
|
280 |
+
"slug_column_mappings = {\n",
|
281 |
+
" \"_median_sale_price_per_sqft\": \"Median Sale Price per Sqft\",\n",
|
282 |
+
" \"_median_sale_price\": \"Median Sale Price\",\n",
|
283 |
+
" \"sales_count\": \"Sales Count\",\n",
|
284 |
+
"}\n",
|
285 |
+
"\n",
|
286 |
"data_frames = []\n",
|
287 |
"\n",
|
288 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
|
|
297 |
" elif \"condo\" in filename:\n",
|
298 |
" cur_df[\"Home Type\"] = \"condo/co-op only\"\n",
|
299 |
"\n",
|
300 |
+
" data_frames = handle_slug_column_mappings(\n",
|
301 |
+
" data_frames, slug_column_mappings, exclude_columns, filename, cur_df\n",
|
302 |
+
" )\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
"\n",
|
304 |
"\n",
|
305 |
"combined_df = get_combined_df(\n",
|
|
|
314 |
" \"Date\",\n",
|
315 |
" ],\n",
|
316 |
")\n",
|
|
|
|
|
317 |
"\n",
|
318 |
+
"combined_df = coalesce_columns(combined_df)\n",
|
319 |
"\n",
|
320 |
"combined_df"
|
321 |
]
|
processors/rentals.ipynb
CHANGED
@@ -2,19 +2,24 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
-
"from helpers import
|
|
|
|
|
|
|
|
|
|
|
13 |
]
|
14 |
},
|
15 |
{
|
16 |
"cell_type": "code",
|
17 |
-
"execution_count":
|
18 |
"metadata": {},
|
19 |
"outputs": [],
|
20 |
"source": [
|
@@ -27,7 +32,7 @@
|
|
27 |
},
|
28 |
{
|
29 |
"cell_type": "code",
|
30 |
-
"execution_count":
|
31 |
"metadata": {},
|
32 |
"outputs": [
|
33 |
{
|
@@ -77,7 +82,7 @@
|
|
77 |
" <td>county</td>\n",
|
78 |
" <td>ID</td>\n",
|
79 |
" <td>all homes plus multifamily</td>\n",
|
80 |
-
" <td>
|
81 |
" <td>Boise City, ID</td>\n",
|
82 |
" <td>16.0</td>\n",
|
83 |
" <td>1.0</td>\n",
|
@@ -95,7 +100,7 @@
|
|
95 |
" <td>county</td>\n",
|
96 |
" <td>ID</td>\n",
|
97 |
" <td>all homes plus multifamily</td>\n",
|
98 |
-
" <td>
|
99 |
" <td>Boise City, ID</td>\n",
|
100 |
" <td>16.0</td>\n",
|
101 |
" <td>1.0</td>\n",
|
@@ -113,7 +118,7 @@
|
|
113 |
" <td>county</td>\n",
|
114 |
" <td>ID</td>\n",
|
115 |
" <td>all homes plus multifamily</td>\n",
|
116 |
-
" <td>
|
117 |
" <td>Boise City, ID</td>\n",
|
118 |
" <td>16.0</td>\n",
|
119 |
" <td>1.0</td>\n",
|
@@ -131,7 +136,7 @@
|
|
131 |
" <td>county</td>\n",
|
132 |
" <td>ID</td>\n",
|
133 |
" <td>all homes plus multifamily</td>\n",
|
134 |
-
" <td>
|
135 |
" <td>Boise City, ID</td>\n",
|
136 |
" <td>16.0</td>\n",
|
137 |
" <td>1.0</td>\n",
|
@@ -149,7 +154,7 @@
|
|
149 |
" <td>county</td>\n",
|
150 |
" <td>ID</td>\n",
|
151 |
" <td>all homes plus multifamily</td>\n",
|
152 |
-
" <td>
|
153 |
" <td>Boise City, ID</td>\n",
|
154 |
" <td>16.0</td>\n",
|
155 |
" <td>1.0</td>\n",
|
@@ -185,8 +190,8 @@
|
|
185 |
" <td>city</td>\n",
|
186 |
" <td>NJ</td>\n",
|
187 |
" <td>all homes plus multifamily</td>\n",
|
188 |
-
" <td>
|
189 |
-
" <td>
|
190 |
" <td>NaN</td>\n",
|
191 |
" <td>NaN</td>\n",
|
192 |
" <td>2023-08-31</td>\n",
|
@@ -203,8 +208,8 @@
|
|
203 |
" <td>city</td>\n",
|
204 |
" <td>NJ</td>\n",
|
205 |
" <td>all homes plus multifamily</td>\n",
|
206 |
-
" <td>
|
207 |
-
" <td>
|
208 |
" <td>NaN</td>\n",
|
209 |
" <td>NaN</td>\n",
|
210 |
" <td>2023-09-30</td>\n",
|
@@ -221,8 +226,8 @@
|
|
221 |
" <td>city</td>\n",
|
222 |
" <td>NJ</td>\n",
|
223 |
" <td>all homes plus multifamily</td>\n",
|
224 |
-
" <td>
|
225 |
-
" <td>
|
226 |
" <td>NaN</td>\n",
|
227 |
" <td>NaN</td>\n",
|
228 |
" <td>2023-10-31</td>\n",
|
@@ -239,8 +244,8 @@
|
|
239 |
" <td>city</td>\n",
|
240 |
" <td>NJ</td>\n",
|
241 |
" <td>all homes plus multifamily</td>\n",
|
242 |
-
" <td>
|
243 |
-
" <td>
|
244 |
" <td>NaN</td>\n",
|
245 |
" <td>NaN</td>\n",
|
246 |
" <td>2023-11-30</td>\n",
|
@@ -257,8 +262,8 @@
|
|
257 |
" <td>city</td>\n",
|
258 |
" <td>NJ</td>\n",
|
259 |
" <td>all homes plus multifamily</td>\n",
|
260 |
-
" <td>
|
261 |
-
" <td>
|
262 |
" <td>NaN</td>\n",
|
263 |
" <td>NaN</td>\n",
|
264 |
" <td>2023-12-31</td>\n",
|
@@ -286,18 +291,31 @@
|
|
286 |
"1258738 857850 713 Cherry Hill city NJ \n",
|
287 |
"1258739 857850 713 Cherry Hill city NJ \n",
|
288 |
"\n",
|
289 |
-
" Home Type State
|
290 |
-
"0 all homes plus multifamily
|
291 |
-
"1 all homes plus multifamily
|
292 |
-
"2 all homes plus multifamily
|
293 |
-
"3 all homes plus multifamily
|
294 |
-
"4 all homes plus multifamily
|
295 |
-
"... ... ...
|
296 |
-
"1258735 all homes plus multifamily
|
297 |
-
"1258736 all homes plus multifamily
|
298 |
-
"1258737 all homes plus multifamily
|
299 |
-
"1258738 all homes plus multifamily
|
300 |
-
"1258739 all homes plus multifamily
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
"\n",
|
302 |
" MunicipalCodeFIPS Date Rent (Smoothed) CountyName \\\n",
|
303 |
"0 1.0 2015-01-31 927.493763 NaN \n",
|
@@ -328,16 +346,16 @@
|
|
328 |
"[1258740 rows x 15 columns]"
|
329 |
]
|
330 |
},
|
331 |
-
"execution_count":
|
332 |
"metadata": {},
|
333 |
"output_type": "execute_result"
|
334 |
}
|
335 |
],
|
336 |
"source": [
|
337 |
-
"# base cols RegionID,SizeRank,RegionName,RegionType,StateName\n",
|
338 |
-
"\n",
|
339 |
"data_frames = []\n",
|
340 |
"\n",
|
|
|
|
|
341 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
342 |
" if filename.endswith(\".csv\"):\n",
|
343 |
" # print(\"processing \" + filename)\n",
|
@@ -402,19 +420,10 @@
|
|
402 |
" elif \"_mfr_\" in filename:\n",
|
403 |
" cur_df[\"Home Type\"] = \"multifamily\"\n",
|
404 |
"\n",
|
405 |
-
"
|
406 |
-
"
|
407 |
-
"\n",
|
408 |
-
" cur_df = get_df(\n",
|
409 |
-
" cur_df,\n",
|
410 |
-
" exclude_columns,\n",
|
411 |
-
" columns_to_pivot,\n",
|
412 |
-
" \"Rent\",\n",
|
413 |
-
" filename,\n",
|
414 |
" )\n",
|
415 |
"\n",
|
416 |
-
" data_frames.append(cur_df)\n",
|
417 |
-
"\n",
|
418 |
"\n",
|
419 |
"combined_df = get_combined_df(\n",
|
420 |
" data_frames,\n",
|
@@ -429,18 +438,14 @@
|
|
429 |
" ],\n",
|
430 |
")\n",
|
431 |
"\n",
|
432 |
-
"\n",
|
433 |
-
"# iterate over rows of combined df and coalesce column values across columns that start with \"Median Sale Price\"\n",
|
434 |
-
"columns_to_coalesce = [\"Rent (Smoothed)\", \"Rent (Smoothed) (Seasonally Adjusted)\"]\n",
|
435 |
-
"\n",
|
436 |
-
"combined_df = coalesce_columns(combined_df, columns_to_coalesce)\n",
|
437 |
"\n",
|
438 |
"combined_df"
|
439 |
]
|
440 |
},
|
441 |
{
|
442 |
"cell_type": "code",
|
443 |
-
"execution_count":
|
444 |
"metadata": {},
|
445 |
"outputs": [
|
446 |
{
|
@@ -591,7 +596,7 @@
|
|
591 |
" <td>city</td>\n",
|
592 |
" <td>all homes plus multifamily</td>\n",
|
593 |
" <td>Camden County</td>\n",
|
594 |
-
" <td>
|
595 |
" <td>NaN</td>\n",
|
596 |
" <td>NaN</td>\n",
|
597 |
" <td>2023-08-31</td>\n",
|
@@ -608,7 +613,7 @@
|
|
608 |
" <td>city</td>\n",
|
609 |
" <td>all homes plus multifamily</td>\n",
|
610 |
" <td>Camden County</td>\n",
|
611 |
-
" <td>
|
612 |
" <td>NaN</td>\n",
|
613 |
" <td>NaN</td>\n",
|
614 |
" <td>2023-09-30</td>\n",
|
@@ -625,7 +630,7 @@
|
|
625 |
" <td>city</td>\n",
|
626 |
" <td>all homes plus multifamily</td>\n",
|
627 |
" <td>Camden County</td>\n",
|
628 |
-
" <td>
|
629 |
" <td>NaN</td>\n",
|
630 |
" <td>NaN</td>\n",
|
631 |
" <td>2023-10-31</td>\n",
|
@@ -642,7 +647,7 @@
|
|
642 |
" <td>city</td>\n",
|
643 |
" <td>all homes plus multifamily</td>\n",
|
644 |
" <td>Camden County</td>\n",
|
645 |
-
" <td>
|
646 |
" <td>NaN</td>\n",
|
647 |
" <td>NaN</td>\n",
|
648 |
" <td>2023-11-30</td>\n",
|
@@ -659,7 +664,7 @@
|
|
659 |
" <td>city</td>\n",
|
660 |
" <td>all homes plus multifamily</td>\n",
|
661 |
" <td>Camden County</td>\n",
|
662 |
-
" <td>
|
663 |
" <td>NaN</td>\n",
|
664 |
" <td>NaN</td>\n",
|
665 |
" <td>2023-12-31</td>\n",
|
@@ -687,31 +692,44 @@
|
|
687 |
"1258738 857850 713 Cherry Hill city \n",
|
688 |
"1258739 857850 713 Cherry Hill city \n",
|
689 |
"\n",
|
690 |
-
" Home Type State
|
691 |
-
"0 all homes plus multifamily Ada County
|
692 |
-
"1 all homes plus multifamily Ada County
|
693 |
-
"2 all homes plus multifamily Ada County
|
694 |
-
"3 all homes plus multifamily Ada County
|
695 |
-
"4 all homes plus multifamily Ada County
|
696 |
-
"... ... ...
|
697 |
-
"1258735 all homes plus multifamily Camden County
|
698 |
-
"1258736 all homes plus multifamily Camden County
|
699 |
-
"1258737 all homes plus multifamily Camden County
|
700 |
-
"1258738 all homes plus multifamily Camden County
|
701 |
-
"1258739 all homes plus multifamily Camden County
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
702 |
"\n",
|
703 |
-
"
|
704 |
-
"0
|
705 |
-
"1
|
706 |
-
"2
|
707 |
-
"3
|
708 |
-
"4
|
709 |
-
"...
|
710 |
-
"1258735
|
711 |
-
"1258736
|
712 |
-
"1258737
|
713 |
-
"1258738
|
714 |
-
"1258739
|
715 |
"\n",
|
716 |
" Rent (Smoothed) (Seasonally Adjusted) City County \n",
|
717 |
"0 927.493763 NaN Ada County \n",
|
@@ -729,7 +747,7 @@
|
|
729 |
"[1258740 rows x 14 columns]"
|
730 |
]
|
731 |
},
|
732 |
-
"execution_count":
|
733 |
"metadata": {},
|
734 |
"output_type": "execute_result"
|
735 |
}
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
+
"from helpers import (\n",
|
13 |
+
" get_combined_df,\n",
|
14 |
+
" coalesce_columns,\n",
|
15 |
+
" save_final_df_as_jsonl,\n",
|
16 |
+
" handle_slug_column_mappings,\n",
|
17 |
+
")"
|
18 |
]
|
19 |
},
|
20 |
{
|
21 |
"cell_type": "code",
|
22 |
+
"execution_count": 3,
|
23 |
"metadata": {},
|
24 |
"outputs": [],
|
25 |
"source": [
|
|
|
32 |
},
|
33 |
{
|
34 |
"cell_type": "code",
|
35 |
+
"execution_count": 7,
|
36 |
"metadata": {},
|
37 |
"outputs": [
|
38 |
{
|
|
|
82 |
" <td>county</td>\n",
|
83 |
" <td>ID</td>\n",
|
84 |
" <td>all homes plus multifamily</td>\n",
|
85 |
+
" <td>16.0</td>\n",
|
86 |
" <td>Boise City, ID</td>\n",
|
87 |
" <td>16.0</td>\n",
|
88 |
" <td>1.0</td>\n",
|
|
|
100 |
" <td>county</td>\n",
|
101 |
" <td>ID</td>\n",
|
102 |
" <td>all homes plus multifamily</td>\n",
|
103 |
+
" <td>16.0</td>\n",
|
104 |
" <td>Boise City, ID</td>\n",
|
105 |
" <td>16.0</td>\n",
|
106 |
" <td>1.0</td>\n",
|
|
|
118 |
" <td>county</td>\n",
|
119 |
" <td>ID</td>\n",
|
120 |
" <td>all homes plus multifamily</td>\n",
|
121 |
+
" <td>16.0</td>\n",
|
122 |
" <td>Boise City, ID</td>\n",
|
123 |
" <td>16.0</td>\n",
|
124 |
" <td>1.0</td>\n",
|
|
|
136 |
" <td>county</td>\n",
|
137 |
" <td>ID</td>\n",
|
138 |
" <td>all homes plus multifamily</td>\n",
|
139 |
+
" <td>16.0</td>\n",
|
140 |
" <td>Boise City, ID</td>\n",
|
141 |
" <td>16.0</td>\n",
|
142 |
" <td>1.0</td>\n",
|
|
|
154 |
" <td>county</td>\n",
|
155 |
" <td>ID</td>\n",
|
156 |
" <td>all homes plus multifamily</td>\n",
|
157 |
+
" <td>16.0</td>\n",
|
158 |
" <td>Boise City, ID</td>\n",
|
159 |
" <td>16.0</td>\n",
|
160 |
" <td>1.0</td>\n",
|
|
|
190 |
" <td>city</td>\n",
|
191 |
" <td>NJ</td>\n",
|
192 |
" <td>all homes plus multifamily</td>\n",
|
193 |
+
" <td>NJ</td>\n",
|
194 |
+
" <td>Philadelphia-Camden-Wilmington, PA-NJ-DE-MD</td>\n",
|
195 |
" <td>NaN</td>\n",
|
196 |
" <td>NaN</td>\n",
|
197 |
" <td>2023-08-31</td>\n",
|
|
|
208 |
" <td>city</td>\n",
|
209 |
" <td>NJ</td>\n",
|
210 |
" <td>all homes plus multifamily</td>\n",
|
211 |
+
" <td>NJ</td>\n",
|
212 |
+
" <td>Philadelphia-Camden-Wilmington, PA-NJ-DE-MD</td>\n",
|
213 |
" <td>NaN</td>\n",
|
214 |
" <td>NaN</td>\n",
|
215 |
" <td>2023-09-30</td>\n",
|
|
|
226 |
" <td>city</td>\n",
|
227 |
" <td>NJ</td>\n",
|
228 |
" <td>all homes plus multifamily</td>\n",
|
229 |
+
" <td>NJ</td>\n",
|
230 |
+
" <td>Philadelphia-Camden-Wilmington, PA-NJ-DE-MD</td>\n",
|
231 |
" <td>NaN</td>\n",
|
232 |
" <td>NaN</td>\n",
|
233 |
" <td>2023-10-31</td>\n",
|
|
|
244 |
" <td>city</td>\n",
|
245 |
" <td>NJ</td>\n",
|
246 |
" <td>all homes plus multifamily</td>\n",
|
247 |
+
" <td>NJ</td>\n",
|
248 |
+
" <td>Philadelphia-Camden-Wilmington, PA-NJ-DE-MD</td>\n",
|
249 |
" <td>NaN</td>\n",
|
250 |
" <td>NaN</td>\n",
|
251 |
" <td>2023-11-30</td>\n",
|
|
|
262 |
" <td>city</td>\n",
|
263 |
" <td>NJ</td>\n",
|
264 |
" <td>all homes plus multifamily</td>\n",
|
265 |
+
" <td>NJ</td>\n",
|
266 |
+
" <td>Philadelphia-Camden-Wilmington, PA-NJ-DE-MD</td>\n",
|
267 |
" <td>NaN</td>\n",
|
268 |
" <td>NaN</td>\n",
|
269 |
" <td>2023-12-31</td>\n",
|
|
|
291 |
"1258738 857850 713 Cherry Hill city NJ \n",
|
292 |
"1258739 857850 713 Cherry Hill city NJ \n",
|
293 |
"\n",
|
294 |
+
" Home Type State \\\n",
|
295 |
+
"0 all homes plus multifamily 16.0 \n",
|
296 |
+
"1 all homes plus multifamily 16.0 \n",
|
297 |
+
"2 all homes plus multifamily 16.0 \n",
|
298 |
+
"3 all homes plus multifamily 16.0 \n",
|
299 |
+
"4 all homes plus multifamily 16.0 \n",
|
300 |
+
"... ... ... \n",
|
301 |
+
"1258735 all homes plus multifamily NJ \n",
|
302 |
+
"1258736 all homes plus multifamily NJ \n",
|
303 |
+
"1258737 all homes plus multifamily NJ \n",
|
304 |
+
"1258738 all homes plus multifamily NJ \n",
|
305 |
+
"1258739 all homes plus multifamily NJ \n",
|
306 |
+
"\n",
|
307 |
+
" Metro StateCodeFIPS \\\n",
|
308 |
+
"0 Boise City, ID 16.0 \n",
|
309 |
+
"1 Boise City, ID 16.0 \n",
|
310 |
+
"2 Boise City, ID 16.0 \n",
|
311 |
+
"3 Boise City, ID 16.0 \n",
|
312 |
+
"4 Boise City, ID 16.0 \n",
|
313 |
+
"... ... ... \n",
|
314 |
+
"1258735 Philadelphia-Camden-Wilmington, PA-NJ-DE-MD NaN \n",
|
315 |
+
"1258736 Philadelphia-Camden-Wilmington, PA-NJ-DE-MD NaN \n",
|
316 |
+
"1258737 Philadelphia-Camden-Wilmington, PA-NJ-DE-MD NaN \n",
|
317 |
+
"1258738 Philadelphia-Camden-Wilmington, PA-NJ-DE-MD NaN \n",
|
318 |
+
"1258739 Philadelphia-Camden-Wilmington, PA-NJ-DE-MD NaN \n",
|
319 |
"\n",
|
320 |
" MunicipalCodeFIPS Date Rent (Smoothed) CountyName \\\n",
|
321 |
"0 1.0 2015-01-31 927.493763 NaN \n",
|
|
|
346 |
"[1258740 rows x 15 columns]"
|
347 |
]
|
348 |
},
|
349 |
+
"execution_count": 7,
|
350 |
"metadata": {},
|
351 |
"output_type": "execute_result"
|
352 |
}
|
353 |
],
|
354 |
"source": [
|
|
|
|
|
355 |
"data_frames = []\n",
|
356 |
"\n",
|
357 |
+
"slug_column_mappings = {\"\": \"Rent\"}\n",
|
358 |
+
"\n",
|
359 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
360 |
" if filename.endswith(\".csv\"):\n",
|
361 |
" # print(\"processing \" + filename)\n",
|
|
|
420 |
" elif \"_mfr_\" in filename:\n",
|
421 |
" cur_df[\"Home Type\"] = \"multifamily\"\n",
|
422 |
"\n",
|
423 |
+
" data_frames = handle_slug_column_mappings(\n",
|
424 |
+
" data_frames, slug_column_mappings, exclude_columns, filename, cur_df\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
" )\n",
|
426 |
"\n",
|
|
|
|
|
427 |
"\n",
|
428 |
"combined_df = get_combined_df(\n",
|
429 |
" data_frames,\n",
|
|
|
438 |
" ],\n",
|
439 |
")\n",
|
440 |
"\n",
|
441 |
+
"combined_df = coalesce_columns(combined_df)\n",
|
|
|
|
|
|
|
|
|
442 |
"\n",
|
443 |
"combined_df"
|
444 |
]
|
445 |
},
|
446 |
{
|
447 |
"cell_type": "code",
|
448 |
+
"execution_count": 8,
|
449 |
"metadata": {},
|
450 |
"outputs": [
|
451 |
{
|
|
|
596 |
" <td>city</td>\n",
|
597 |
" <td>all homes plus multifamily</td>\n",
|
598 |
" <td>Camden County</td>\n",
|
599 |
+
" <td>Philadelphia-Camden-Wilmington, PA-NJ-DE-MD</td>\n",
|
600 |
" <td>NaN</td>\n",
|
601 |
" <td>NaN</td>\n",
|
602 |
" <td>2023-08-31</td>\n",
|
|
|
613 |
" <td>city</td>\n",
|
614 |
" <td>all homes plus multifamily</td>\n",
|
615 |
" <td>Camden County</td>\n",
|
616 |
+
" <td>Philadelphia-Camden-Wilmington, PA-NJ-DE-MD</td>\n",
|
617 |
" <td>NaN</td>\n",
|
618 |
" <td>NaN</td>\n",
|
619 |
" <td>2023-09-30</td>\n",
|
|
|
630 |
" <td>city</td>\n",
|
631 |
" <td>all homes plus multifamily</td>\n",
|
632 |
" <td>Camden County</td>\n",
|
633 |
+
" <td>Philadelphia-Camden-Wilmington, PA-NJ-DE-MD</td>\n",
|
634 |
" <td>NaN</td>\n",
|
635 |
" <td>NaN</td>\n",
|
636 |
" <td>2023-10-31</td>\n",
|
|
|
647 |
" <td>city</td>\n",
|
648 |
" <td>all homes plus multifamily</td>\n",
|
649 |
" <td>Camden County</td>\n",
|
650 |
+
" <td>Philadelphia-Camden-Wilmington, PA-NJ-DE-MD</td>\n",
|
651 |
" <td>NaN</td>\n",
|
652 |
" <td>NaN</td>\n",
|
653 |
" <td>2023-11-30</td>\n",
|
|
|
664 |
" <td>city</td>\n",
|
665 |
" <td>all homes plus multifamily</td>\n",
|
666 |
" <td>Camden County</td>\n",
|
667 |
+
" <td>Philadelphia-Camden-Wilmington, PA-NJ-DE-MD</td>\n",
|
668 |
" <td>NaN</td>\n",
|
669 |
" <td>NaN</td>\n",
|
670 |
" <td>2023-12-31</td>\n",
|
|
|
692 |
"1258738 857850 713 Cherry Hill city \n",
|
693 |
"1258739 857850 713 Cherry Hill city \n",
|
694 |
"\n",
|
695 |
+
" Home Type State \\\n",
|
696 |
+
"0 all homes plus multifamily Ada County \n",
|
697 |
+
"1 all homes plus multifamily Ada County \n",
|
698 |
+
"2 all homes plus multifamily Ada County \n",
|
699 |
+
"3 all homes plus multifamily Ada County \n",
|
700 |
+
"4 all homes plus multifamily Ada County \n",
|
701 |
+
"... ... ... \n",
|
702 |
+
"1258735 all homes plus multifamily Camden County \n",
|
703 |
+
"1258736 all homes plus multifamily Camden County \n",
|
704 |
+
"1258737 all homes plus multifamily Camden County \n",
|
705 |
+
"1258738 all homes plus multifamily Camden County \n",
|
706 |
+
"1258739 all homes plus multifamily Camden County \n",
|
707 |
+
"\n",
|
708 |
+
" Metro StateCodeFIPS \\\n",
|
709 |
+
"0 Boise City, ID 16.0 \n",
|
710 |
+
"1 Boise City, ID 16.0 \n",
|
711 |
+
"2 Boise City, ID 16.0 \n",
|
712 |
+
"3 Boise City, ID 16.0 \n",
|
713 |
+
"4 Boise City, ID 16.0 \n",
|
714 |
+
"... ... ... \n",
|
715 |
+
"1258735 Philadelphia-Camden-Wilmington, PA-NJ-DE-MD NaN \n",
|
716 |
+
"1258736 Philadelphia-Camden-Wilmington, PA-NJ-DE-MD NaN \n",
|
717 |
+
"1258737 Philadelphia-Camden-Wilmington, PA-NJ-DE-MD NaN \n",
|
718 |
+
"1258738 Philadelphia-Camden-Wilmington, PA-NJ-DE-MD NaN \n",
|
719 |
+
"1258739 Philadelphia-Camden-Wilmington, PA-NJ-DE-MD NaN \n",
|
720 |
"\n",
|
721 |
+
" MunicipalCodeFIPS Date Rent (Smoothed) \\\n",
|
722 |
+
"0 1.0 2015-01-31 927.493763 \n",
|
723 |
+
"1 1.0 2015-02-28 931.690623 \n",
|
724 |
+
"2 1.0 2015-03-31 932.568601 \n",
|
725 |
+
"3 1.0 2015-04-30 933.148134 \n",
|
726 |
+
"4 1.0 2015-05-31 941.045724 \n",
|
727 |
+
"... ... ... ... \n",
|
728 |
+
"1258735 NaN 2023-08-31 2291.604800 \n",
|
729 |
+
"1258736 NaN 2023-09-30 2296.188906 \n",
|
730 |
+
"1258737 NaN 2023-10-31 2292.270938 \n",
|
731 |
+
"1258738 NaN 2023-11-30 2253.417140 \n",
|
732 |
+
"1258739 NaN 2023-12-31 2280.830303 \n",
|
733 |
"\n",
|
734 |
" Rent (Smoothed) (Seasonally Adjusted) City County \n",
|
735 |
"0 927.493763 NaN Ada County \n",
|
|
|
747 |
"[1258740 rows x 14 columns]"
|
748 |
]
|
749 |
},
|
750 |
+
"execution_count": 8,
|
751 |
"metadata": {},
|
752 |
"output_type": "execute_result"
|
753 |
}
|
processors/sales.ipynb
CHANGED
@@ -9,7 +9,12 @@
|
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
-
"from helpers import
|
|
|
|
|
|
|
|
|
|
|
13 |
]
|
14 |
},
|
15 |
{
|
@@ -468,8 +473,6 @@
|
|
468 |
}
|
469 |
],
|
470 |
"source": [
|
471 |
-
"# base cols RegionID,SizeRank,RegionName,RegionType,StateName\n",
|
472 |
-
"\n",
|
473 |
"exclude_columns = [\n",
|
474 |
" \"RegionID\",\n",
|
475 |
" \"SizeRank\",\n",
|
@@ -493,33 +496,20 @@
|
|
493 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
494 |
" if filename.endswith(\".csv\"):\n",
|
495 |
" print(\"processing \" + filename)\n",
|
496 |
-
" cur_df = pd.read_csv(os.path.join(FULL_DATA_DIR_PATH, filename))\n",
|
497 |
-
"\n",
|
498 |
" # ignore monthly data for now since it is redundant\n",
|
499 |
-
" if \"
|
500 |
" continue\n",
|
501 |
"\n",
|
|
|
|
|
502 |
" if \"_sfrcondo_\" in filename:\n",
|
503 |
" cur_df[\"Home Type\"] = \"all homes\"\n",
|
504 |
" elif \"_sfr_\" in filename:\n",
|
505 |
" cur_df[\"Home Type\"] = \"SFR\"\n",
|
506 |
"\n",
|
507 |
-
"
|
508 |
-
"
|
509 |
-
"\n",
|
510 |
-
" # iterate over slug column mappings and get df\n",
|
511 |
-
" for slug, col_name in slug_column_mappings.items():\n",
|
512 |
-
" if slug in filename:\n",
|
513 |
-
" cur_df = get_df(\n",
|
514 |
-
" cur_df,\n",
|
515 |
-
" exclude_columns,\n",
|
516 |
-
" columns_to_pivot,\n",
|
517 |
-
" col_name,\n",
|
518 |
-
" filename,\n",
|
519 |
-
" )\n",
|
520 |
-
"\n",
|
521 |
-
" data_frames.append(cur_df)\n",
|
522 |
-
" break\n",
|
523 |
"\n",
|
524 |
"\n",
|
525 |
"combined_df = get_combined_df(\n",
|
@@ -535,23 +525,7 @@
|
|
535 |
" ],\n",
|
536 |
")\n",
|
537 |
"\n",
|
538 |
-
"
|
539 |
-
"columns_to_coalesce = [\n",
|
540 |
-
" \"Mean Sale to List Ratio (Smoothed)\"\n",
|
541 |
-
" \"Median Sale to List Ratio\"\n",
|
542 |
-
" \"Median Sale Price\"\n",
|
543 |
-
" \"% Sold Below List (Smoothed)\",\n",
|
544 |
-
" \"Median Sale Price (Smoothed) (Seasonally Adjusted)\",\n",
|
545 |
-
" \"% Sold Below List\",\n",
|
546 |
-
" \"Median Sale Price (Smoothed)\",\n",
|
547 |
-
" \"Median Sale to List Ratio (Smoothed)\",\n",
|
548 |
-
" \"% Sold Above List\",\n",
|
549 |
-
" \"Nowcast\",\n",
|
550 |
-
" \"Mean Sale to List Ratio\",\n",
|
551 |
-
" \"% Sold Above List (Smoothed)\",\n",
|
552 |
-
"]\n",
|
553 |
-
"\n",
|
554 |
-
"combined_df = coalesce_columns(combined_df, columns_to_coalesce)\n",
|
555 |
"\n",
|
556 |
"combined_df"
|
557 |
]
|
|
|
9 |
"import pandas as pd\n",
|
10 |
"import os\n",
|
11 |
"\n",
|
12 |
+
"from helpers import (\n",
|
13 |
+
" get_combined_df,\n",
|
14 |
+
" coalesce_columns,\n",
|
15 |
+
" save_final_df_as_jsonl,\n",
|
16 |
+
" handle_slug_column_mappings,\n",
|
17 |
+
")"
|
18 |
]
|
19 |
},
|
20 |
{
|
|
|
473 |
}
|
474 |
],
|
475 |
"source": [
|
|
|
|
|
476 |
"exclude_columns = [\n",
|
477 |
" \"RegionID\",\n",
|
478 |
" \"SizeRank\",\n",
|
|
|
496 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
497 |
" if filename.endswith(\".csv\"):\n",
|
498 |
" print(\"processing \" + filename)\n",
|
|
|
|
|
499 |
" # ignore monthly data for now since it is redundant\n",
|
500 |
+
" if \"month\" in filename:\n",
|
501 |
" continue\n",
|
502 |
"\n",
|
503 |
+
" cur_df = pd.read_csv(os.path.join(FULL_DATA_DIR_PATH, filename))\n",
|
504 |
+
"\n",
|
505 |
" if \"_sfrcondo_\" in filename:\n",
|
506 |
" cur_df[\"Home Type\"] = \"all homes\"\n",
|
507 |
" elif \"_sfr_\" in filename:\n",
|
508 |
" cur_df[\"Home Type\"] = \"SFR\"\n",
|
509 |
"\n",
|
510 |
+
" data_frames = handle_slug_column_mappings(\n",
|
511 |
+
" data_frames, slug_column_mappings, exclude_columns, filename, cur_df\n",
|
512 |
+
" )\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
513 |
"\n",
|
514 |
"\n",
|
515 |
"combined_df = get_combined_df(\n",
|
|
|
525 |
" ],\n",
|
526 |
")\n",
|
527 |
"\n",
|
528 |
+
"combined_df = coalesce_columns(combined_df)\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
529 |
"\n",
|
530 |
"combined_df"
|
531 |
]
|