fix: update handling of merges
Browse files- processed/for_sale_listings/final.jsonl +2 -2
- processed/new_constructions/final.jsonl +2 -2
- processed/rentals/final.jsonl +2 -2
- processors/for_sale_listings.ipynb +246 -207
- processors/new_constructions.ipynb +163 -169
- processors/rentals.ipynb +250 -51
- tester.ipynb +6 -6
processed/for_sale_listings/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:f449b3db5edd6115f4be4da56992047d9fa50c24cbd85e5715f041bf8b1d5fda
|
3 |
+
size 215422186
|
processed/new_constructions/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:276b20bd2011faa1fb59f58892ef16b8bbfbb8111a10c7e8d4f433a9226bf3c5
|
3 |
+
size 10903095
|
processed/rentals/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:d30311278d0da51a72097cb296e419eeafeb47a63bcf169975900c6e3252fa29
|
3 |
+
size 20682905
|
processors/for_sale_listings.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
@@ -12,7 +12,7 @@
|
|
12 |
},
|
13 |
{
|
14 |
"cell_type": "code",
|
15 |
-
"execution_count":
|
16 |
"metadata": {},
|
17 |
"outputs": [],
|
18 |
"source": [
|
@@ -25,7 +25,7 @@
|
|
25 |
},
|
26 |
{
|
27 |
"cell_type": "code",
|
28 |
-
"execution_count":
|
29 |
"metadata": {},
|
30 |
"outputs": [
|
31 |
{
|
@@ -86,12 +86,12 @@
|
|
86 |
" <th>StateName</th>\n",
|
87 |
" <th>Home Type</th>\n",
|
88 |
" <th>Date</th>\n",
|
|
|
89 |
" <th>Median Listing Price</th>\n",
|
90 |
" <th>Median Listing Price (Smoothed)</th>\n",
|
|
|
91 |
" <th>New Listings</th>\n",
|
92 |
" <th>New Listings (Smoothed)</th>\n",
|
93 |
-
" <th>New Pending (Smoothed)</th>\n",
|
94 |
-
" <th>New Pending</th>\n",
|
95 |
" </tr>\n",
|
96 |
" </thead>\n",
|
97 |
" <tbody>\n",
|
@@ -102,14 +102,14 @@
|
|
102 |
" <td>United States</td>\n",
|
103 |
" <td>country</td>\n",
|
104 |
" <td>NaN</td>\n",
|
105 |
-
" <td>
|
106 |
-
" <td>2018-01-
|
107 |
" <td>NaN</td>\n",
|
|
|
108 |
" <td>NaN</td>\n",
|
109 |
" <td>NaN</td>\n",
|
110 |
" <td>NaN</td>\n",
|
111 |
" <td>NaN</td>\n",
|
112 |
-
" <td>24766.0</td>\n",
|
113 |
" </tr>\n",
|
114 |
" <tr>\n",
|
115 |
" <th>1</th>\n",
|
@@ -119,9 +119,9 @@
|
|
119 |
" <td>country</td>\n",
|
120 |
" <td>NaN</td>\n",
|
121 |
" <td>SFR</td>\n",
|
122 |
-
" <td>2018-01-
|
123 |
-
" <td>259000.0</td>\n",
|
124 |
" <td>NaN</td>\n",
|
|
|
125 |
" <td>NaN</td>\n",
|
126 |
" <td>NaN</td>\n",
|
127 |
" <td>NaN</td>\n",
|
@@ -134,14 +134,14 @@
|
|
134 |
" <td>United States</td>\n",
|
135 |
" <td>country</td>\n",
|
136 |
" <td>NaN</td>\n",
|
137 |
-
" <td>
|
138 |
-
" <td>2018-01-
|
|
|
139 |
" <td>259900.0</td>\n",
|
140 |
" <td>NaN</td>\n",
|
141 |
-
" <td>71177.0</td>\n",
|
142 |
" <td>NaN</td>\n",
|
143 |
" <td>NaN</td>\n",
|
144 |
-
" <td>
|
145 |
" </tr>\n",
|
146 |
" <tr>\n",
|
147 |
" <th>3</th>\n",
|
@@ -151,9 +151,9 @@
|
|
151 |
" <td>country</td>\n",
|
152 |
" <td>NaN</td>\n",
|
153 |
" <td>SFR</td>\n",
|
154 |
-
" <td>2018-01-
|
155 |
-
" <td>259900.0</td>\n",
|
156 |
" <td>NaN</td>\n",
|
|
|
157 |
" <td>NaN</td>\n",
|
158 |
" <td>NaN</td>\n",
|
159 |
" <td>NaN</td>\n",
|
@@ -166,14 +166,14 @@
|
|
166 |
" <td>United States</td>\n",
|
167 |
" <td>country</td>\n",
|
168 |
" <td>NaN</td>\n",
|
169 |
-
" <td>
|
170 |
-
" <td>2018-
|
171 |
-
" <td>
|
|
|
|
|
172 |
" <td>NaN</td>\n",
|
173 |
-
" <td>72625.0</td>\n",
|
174 |
" <td>NaN</td>\n",
|
175 |
" <td>NaN</td>\n",
|
176 |
-
" <td>38281.0</td>\n",
|
177 |
" </tr>\n",
|
178 |
" <tr>\n",
|
179 |
" <th>...</th>\n",
|
@@ -192,71 +192,71 @@
|
|
192 |
" <td>...</td>\n",
|
193 |
" </tr>\n",
|
194 |
" <tr>\n",
|
195 |
-
" <th>
|
196 |
" <td>845172</td>\n",
|
197 |
" <td>769</td>\n",
|
198 |
" <td>Winfield, KS</td>\n",
|
199 |
" <td>msa</td>\n",
|
200 |
" <td>KS</td>\n",
|
201 |
" <td>all homes</td>\n",
|
202 |
-
" <td>2023-12-
|
|
|
|
|
|
|
203 |
" <td>NaN</td>\n",
|
204 |
-
" <td>136233.0</td>\n",
|
205 |
" <td>NaN</td>\n",
|
206 |
-
" <td>28.0</td>\n",
|
207 |
" <td>NaN</td>\n",
|
208 |
-
" <td>24.0</td>\n",
|
209 |
" </tr>\n",
|
210 |
" <tr>\n",
|
211 |
-
" <th>
|
212 |
" <td>845172</td>\n",
|
213 |
" <td>769</td>\n",
|
214 |
" <td>Winfield, KS</td>\n",
|
215 |
" <td>msa</td>\n",
|
216 |
" <td>KS</td>\n",
|
217 |
-
" <td>
|
218 |
-
" <td>
|
219 |
-
" <td>NaN</td>\n",
|
220 |
-
" <td>131088.0</td>\n",
|
221 |
" <td>NaN</td>\n",
|
|
|
|
|
222 |
" <td>NaN</td>\n",
|
223 |
" <td>NaN</td>\n",
|
224 |
" <td>NaN</td>\n",
|
225 |
" </tr>\n",
|
226 |
" <tr>\n",
|
227 |
-
" <th>
|
228 |
" <td>845172</td>\n",
|
229 |
" <td>769</td>\n",
|
230 |
" <td>Winfield, KS</td>\n",
|
231 |
" <td>msa</td>\n",
|
232 |
" <td>KS</td>\n",
|
233 |
-
" <td>
|
234 |
-
" <td>
|
235 |
-
" <td>135450.0</td>\n",
|
236 |
-
" <td>NaN</td>\n",
|
237 |
" <td>NaN</td>\n",
|
|
|
|
|
238 |
" <td>NaN</td>\n",
|
239 |
" <td>NaN</td>\n",
|
240 |
" <td>NaN</td>\n",
|
241 |
" </tr>\n",
|
242 |
" <tr>\n",
|
243 |
-
" <th>
|
244 |
" <td>845172</td>\n",
|
245 |
" <td>769</td>\n",
|
246 |
" <td>Winfield, KS</td>\n",
|
247 |
" <td>msa</td>\n",
|
248 |
" <td>KS</td>\n",
|
249 |
" <td>all homes</td>\n",
|
250 |
-
" <td>
|
251 |
-
" <td>
|
252 |
-
" <td>
|
253 |
-
" <td>
|
254 |
-
" <td>
|
255 |
-
" <td>
|
256 |
-
" <td>
|
257 |
" </tr>\n",
|
258 |
" <tr>\n",
|
259 |
-
" <th>
|
260 |
" <td>845172</td>\n",
|
261 |
" <td>769</td>\n",
|
262 |
" <td>Winfield, KS</td>\n",
|
@@ -266,73 +266,73 @@
|
|
266 |
" <td>2024-01-06</td>\n",
|
267 |
" <td>NaN</td>\n",
|
268 |
" <td>121488.0</td>\n",
|
269 |
-
" <td>
|
270 |
" <td>NaN</td>\n",
|
271 |
" <td>NaN</td>\n",
|
272 |
" <td>NaN</td>\n",
|
273 |
" </tr>\n",
|
274 |
" </tbody>\n",
|
275 |
"</table>\n",
|
276 |
-
"<p>
|
277 |
"</div>"
|
278 |
],
|
279 |
"text/plain": [
|
280 |
-
"
|
281 |
-
"0
|
282 |
-
"1
|
283 |
-
"2
|
284 |
-
"3
|
285 |
-
"4
|
286 |
-
"...
|
287 |
-
"
|
288 |
-
"
|
289 |
-
"
|
290 |
-
"
|
291 |
-
"
|
292 |
"\n",
|
293 |
-
"
|
294 |
-
"0
|
295 |
-
"1
|
296 |
-
"2
|
297 |
-
"3
|
298 |
-
"4
|
299 |
-
"...
|
300 |
-
"
|
301 |
-
"
|
302 |
-
"
|
303 |
-
"
|
304 |
-
"
|
305 |
"\n",
|
306 |
-
"
|
307 |
-
"0
|
308 |
-
"1
|
309 |
-
"2
|
310 |
-
"3
|
311 |
-
"4
|
312 |
-
"...
|
313 |
-
"
|
314 |
-
"
|
315 |
-
"
|
316 |
-
"
|
317 |
-
"
|
318 |
"\n",
|
319 |
-
"
|
320 |
-
"0
|
321 |
-
"1
|
322 |
-
"2
|
323 |
-
"3
|
324 |
-
"4
|
325 |
-
"...
|
326 |
-
"
|
327 |
-
"
|
328 |
-
"
|
329 |
-
"
|
330 |
-
"
|
331 |
"\n",
|
332 |
-
"[
|
333 |
]
|
334 |
},
|
335 |
-
"execution_count":
|
336 |
"metadata": {},
|
337 |
"output_type": "execute_result"
|
338 |
}
|
@@ -349,7 +349,7 @@
|
|
349 |
" \"Home Type\",\n",
|
350 |
"]\n",
|
351 |
"\n",
|
352 |
-
"
|
353 |
"\n",
|
354 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
355 |
" if filename.endswith(\".csv\"):\n",
|
@@ -384,7 +384,7 @@
|
|
384 |
" else \"Median Listing Price (Smoothed)\"\n",
|
385 |
" ),\n",
|
386 |
" )\n",
|
387 |
-
"
|
388 |
"\n",
|
389 |
" elif \"_new_listings_\" in filename:\n",
|
390 |
" cur_df = pd.melt(\n",
|
@@ -396,7 +396,7 @@
|
|
396 |
" \"New Listings\" if not smoothed else \"New Listings (Smoothed)\"\n",
|
397 |
" ),\n",
|
398 |
" )\n",
|
399 |
-
"
|
400 |
"\n",
|
401 |
" elif \"new_pending\" in filename:\n",
|
402 |
" cur_df = pd.melt(\n",
|
@@ -406,7 +406,7 @@
|
|
406 |
" var_name=\"Date\",\n",
|
407 |
" value_name=\"New Pending\" if not smoothed else \"New Pending (Smoothed)\",\n",
|
408 |
" )\n",
|
409 |
-
"
|
410 |
"\n",
|
411 |
"matching_cols = [\n",
|
412 |
" \"RegionID\",\n",
|
@@ -418,25 +418,64 @@
|
|
418 |
" \"Home Type\",\n",
|
419 |
"]\n",
|
420 |
"\n",
|
421 |
-
"combined_batches = [pd.concat(cur_batch) for cur_batch in batches.values()]\n",
|
422 |
"\n",
|
423 |
-
"
|
424 |
-
" combined_df =
|
425 |
-
"
|
426 |
-
"
|
427 |
-
"
|
428 |
-
"
|
429 |
-
"
|
430 |
-
"
|
431 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
432 |
"\n",
|
433 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
"combined_df"
|
435 |
]
|
436 |
},
|
437 |
{
|
438 |
"cell_type": "code",
|
439 |
-
"execution_count":
|
440 |
"metadata": {},
|
441 |
"outputs": [
|
442 |
{
|
@@ -467,12 +506,12 @@
|
|
467 |
" <th>State</th>\n",
|
468 |
" <th>Home Type</th>\n",
|
469 |
" <th>Date</th>\n",
|
|
|
470 |
" <th>Median Listing Price</th>\n",
|
471 |
" <th>Median Listing Price (Smoothed)</th>\n",
|
|
|
472 |
" <th>New Listings</th>\n",
|
473 |
" <th>New Listings (Smoothed)</th>\n",
|
474 |
-
" <th>New Pending (Smoothed)</th>\n",
|
475 |
-
" <th>New Pending</th>\n",
|
476 |
" </tr>\n",
|
477 |
" </thead>\n",
|
478 |
" <tbody>\n",
|
@@ -483,14 +522,14 @@
|
|
483 |
" <td>United States</td>\n",
|
484 |
" <td>country</td>\n",
|
485 |
" <td>NaN</td>\n",
|
486 |
-
" <td>
|
487 |
-
" <td>2018-01-
|
488 |
" <td>NaN</td>\n",
|
|
|
489 |
" <td>NaN</td>\n",
|
490 |
" <td>NaN</td>\n",
|
491 |
" <td>NaN</td>\n",
|
492 |
" <td>NaN</td>\n",
|
493 |
-
" <td>24766.0</td>\n",
|
494 |
" </tr>\n",
|
495 |
" <tr>\n",
|
496 |
" <th>1</th>\n",
|
@@ -500,9 +539,9 @@
|
|
500 |
" <td>country</td>\n",
|
501 |
" <td>NaN</td>\n",
|
502 |
" <td>SFR</td>\n",
|
503 |
-
" <td>2018-01-
|
504 |
-
" <td>259000.0</td>\n",
|
505 |
" <td>NaN</td>\n",
|
|
|
506 |
" <td>NaN</td>\n",
|
507 |
" <td>NaN</td>\n",
|
508 |
" <td>NaN</td>\n",
|
@@ -515,14 +554,14 @@
|
|
515 |
" <td>United States</td>\n",
|
516 |
" <td>country</td>\n",
|
517 |
" <td>NaN</td>\n",
|
518 |
-
" <td>
|
519 |
-
" <td>2018-01-
|
|
|
520 |
" <td>259900.0</td>\n",
|
521 |
" <td>NaN</td>\n",
|
522 |
-
" <td>71177.0</td>\n",
|
523 |
" <td>NaN</td>\n",
|
524 |
" <td>NaN</td>\n",
|
525 |
-
" <td>
|
526 |
" </tr>\n",
|
527 |
" <tr>\n",
|
528 |
" <th>3</th>\n",
|
@@ -532,9 +571,9 @@
|
|
532 |
" <td>country</td>\n",
|
533 |
" <td>NaN</td>\n",
|
534 |
" <td>SFR</td>\n",
|
535 |
-
" <td>2018-01-
|
536 |
-
" <td>259900.0</td>\n",
|
537 |
" <td>NaN</td>\n",
|
|
|
538 |
" <td>NaN</td>\n",
|
539 |
" <td>NaN</td>\n",
|
540 |
" <td>NaN</td>\n",
|
@@ -547,14 +586,14 @@
|
|
547 |
" <td>United States</td>\n",
|
548 |
" <td>country</td>\n",
|
549 |
" <td>NaN</td>\n",
|
550 |
-
" <td>
|
551 |
-
" <td>2018-
|
552 |
-
" <td>
|
|
|
|
|
553 |
" <td>NaN</td>\n",
|
554 |
-
" <td>72625.0</td>\n",
|
555 |
" <td>NaN</td>\n",
|
556 |
" <td>NaN</td>\n",
|
557 |
-
" <td>38281.0</td>\n",
|
558 |
" </tr>\n",
|
559 |
" <tr>\n",
|
560 |
" <th>...</th>\n",
|
@@ -573,71 +612,71 @@
|
|
573 |
" <td>...</td>\n",
|
574 |
" </tr>\n",
|
575 |
" <tr>\n",
|
576 |
-
" <th>
|
577 |
" <td>845172</td>\n",
|
578 |
" <td>769</td>\n",
|
579 |
" <td>Winfield, KS</td>\n",
|
580 |
" <td>msa</td>\n",
|
581 |
" <td>KS</td>\n",
|
582 |
" <td>all homes</td>\n",
|
583 |
-
" <td>2023-12-
|
|
|
|
|
|
|
584 |
" <td>NaN</td>\n",
|
585 |
-
" <td>136233.0</td>\n",
|
586 |
" <td>NaN</td>\n",
|
587 |
-
" <td>28.0</td>\n",
|
588 |
" <td>NaN</td>\n",
|
589 |
-
" <td>24.0</td>\n",
|
590 |
" </tr>\n",
|
591 |
" <tr>\n",
|
592 |
-
" <th>
|
593 |
" <td>845172</td>\n",
|
594 |
" <td>769</td>\n",
|
595 |
" <td>Winfield, KS</td>\n",
|
596 |
" <td>msa</td>\n",
|
597 |
" <td>KS</td>\n",
|
598 |
-
" <td>
|
599 |
-
" <td>
|
600 |
-
" <td>NaN</td>\n",
|
601 |
-
" <td>131088.0</td>\n",
|
602 |
" <td>NaN</td>\n",
|
|
|
|
|
603 |
" <td>NaN</td>\n",
|
604 |
" <td>NaN</td>\n",
|
605 |
" <td>NaN</td>\n",
|
606 |
" </tr>\n",
|
607 |
" <tr>\n",
|
608 |
-
" <th>
|
609 |
" <td>845172</td>\n",
|
610 |
" <td>769</td>\n",
|
611 |
" <td>Winfield, KS</td>\n",
|
612 |
" <td>msa</td>\n",
|
613 |
" <td>KS</td>\n",
|
614 |
-
" <td>
|
615 |
-
" <td>
|
616 |
-
" <td>135450.0</td>\n",
|
617 |
-
" <td>NaN</td>\n",
|
618 |
" <td>NaN</td>\n",
|
|
|
|
|
619 |
" <td>NaN</td>\n",
|
620 |
" <td>NaN</td>\n",
|
621 |
" <td>NaN</td>\n",
|
622 |
" </tr>\n",
|
623 |
" <tr>\n",
|
624 |
-
" <th>
|
625 |
" <td>845172</td>\n",
|
626 |
" <td>769</td>\n",
|
627 |
" <td>Winfield, KS</td>\n",
|
628 |
" <td>msa</td>\n",
|
629 |
" <td>KS</td>\n",
|
630 |
" <td>all homes</td>\n",
|
631 |
-
" <td>
|
632 |
-
" <td>
|
633 |
-
" <td>
|
634 |
-
" <td>
|
635 |
-
" <td>
|
636 |
-
" <td>
|
637 |
-
" <td>
|
638 |
" </tr>\n",
|
639 |
" <tr>\n",
|
640 |
-
" <th>
|
641 |
" <td>845172</td>\n",
|
642 |
" <td>769</td>\n",
|
643 |
" <td>Winfield, KS</td>\n",
|
@@ -647,73 +686,73 @@
|
|
647 |
" <td>2024-01-06</td>\n",
|
648 |
" <td>NaN</td>\n",
|
649 |
" <td>121488.0</td>\n",
|
650 |
-
" <td>
|
651 |
" <td>NaN</td>\n",
|
652 |
" <td>NaN</td>\n",
|
653 |
" <td>NaN</td>\n",
|
654 |
" </tr>\n",
|
655 |
" </tbody>\n",
|
656 |
"</table>\n",
|
657 |
-
"<p>
|
658 |
"</div>"
|
659 |
],
|
660 |
"text/plain": [
|
661 |
-
"
|
662 |
-
"0
|
663 |
-
"1
|
664 |
-
"2
|
665 |
-
"3
|
666 |
-
"4
|
667 |
-
"...
|
668 |
-
"
|
669 |
-
"
|
670 |
-
"
|
671 |
-
"
|
672 |
-
"
|
673 |
"\n",
|
674 |
-
"
|
675 |
-
"0
|
676 |
-
"1
|
677 |
-
"2
|
678 |
-
"3
|
679 |
-
"4
|
680 |
-
"...
|
681 |
-
"
|
682 |
-
"
|
683 |
-
"
|
684 |
-
"
|
685 |
-
"
|
686 |
"\n",
|
687 |
-
"
|
688 |
-
"0
|
689 |
-
"1
|
690 |
-
"2
|
691 |
-
"3
|
692 |
-
"4
|
693 |
-
"...
|
694 |
-
"
|
695 |
-
"
|
696 |
-
"
|
697 |
-
"
|
698 |
-
"
|
699 |
"\n",
|
700 |
-
"
|
701 |
-
"0
|
702 |
-
"1
|
703 |
-
"2
|
704 |
-
"3
|
705 |
-
"4
|
706 |
-
"...
|
707 |
-
"
|
708 |
-
"
|
709 |
-
"
|
710 |
-
"
|
711 |
-
"
|
712 |
"\n",
|
713 |
-
"[
|
714 |
]
|
715 |
},
|
716 |
-
"execution_count":
|
717 |
"metadata": {},
|
718 |
"output_type": "execute_result"
|
719 |
}
|
@@ -735,7 +774,7 @@
|
|
735 |
},
|
736 |
{
|
737 |
"cell_type": "code",
|
738 |
-
"execution_count":
|
739 |
"metadata": {},
|
740 |
"outputs": [],
|
741 |
"source": [
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
|
|
12 |
},
|
13 |
{
|
14 |
"cell_type": "code",
|
15 |
+
"execution_count": 3,
|
16 |
"metadata": {},
|
17 |
"outputs": [],
|
18 |
"source": [
|
|
|
25 |
},
|
26 |
{
|
27 |
"cell_type": "code",
|
28 |
+
"execution_count": 5,
|
29 |
"metadata": {},
|
30 |
"outputs": [
|
31 |
{
|
|
|
86 |
" <th>StateName</th>\n",
|
87 |
" <th>Home Type</th>\n",
|
88 |
" <th>Date</th>\n",
|
89 |
+
" <th>New Pending (Smoothed)</th>\n",
|
90 |
" <th>Median Listing Price</th>\n",
|
91 |
" <th>Median Listing Price (Smoothed)</th>\n",
|
92 |
+
" <th>New Pending</th>\n",
|
93 |
" <th>New Listings</th>\n",
|
94 |
" <th>New Listings (Smoothed)</th>\n",
|
|
|
|
|
95 |
" </tr>\n",
|
96 |
" </thead>\n",
|
97 |
" <tbody>\n",
|
|
|
102 |
" <td>United States</td>\n",
|
103 |
" <td>country</td>\n",
|
104 |
" <td>NaN</td>\n",
|
105 |
+
" <td>SFR</td>\n",
|
106 |
+
" <td>2018-01-13</td>\n",
|
107 |
" <td>NaN</td>\n",
|
108 |
+
" <td>259000.0</td>\n",
|
109 |
" <td>NaN</td>\n",
|
110 |
" <td>NaN</td>\n",
|
111 |
" <td>NaN</td>\n",
|
112 |
" <td>NaN</td>\n",
|
|
|
113 |
" </tr>\n",
|
114 |
" <tr>\n",
|
115 |
" <th>1</th>\n",
|
|
|
119 |
" <td>country</td>\n",
|
120 |
" <td>NaN</td>\n",
|
121 |
" <td>SFR</td>\n",
|
122 |
+
" <td>2018-01-20</td>\n",
|
|
|
123 |
" <td>NaN</td>\n",
|
124 |
+
" <td>259900.0</td>\n",
|
125 |
" <td>NaN</td>\n",
|
126 |
" <td>NaN</td>\n",
|
127 |
" <td>NaN</td>\n",
|
|
|
134 |
" <td>United States</td>\n",
|
135 |
" <td>country</td>\n",
|
136 |
" <td>NaN</td>\n",
|
137 |
+
" <td>SFR</td>\n",
|
138 |
+
" <td>2018-01-27</td>\n",
|
139 |
+
" <td>NaN</td>\n",
|
140 |
" <td>259900.0</td>\n",
|
141 |
" <td>NaN</td>\n",
|
|
|
142 |
" <td>NaN</td>\n",
|
143 |
" <td>NaN</td>\n",
|
144 |
+
" <td>NaN</td>\n",
|
145 |
" </tr>\n",
|
146 |
" <tr>\n",
|
147 |
" <th>3</th>\n",
|
|
|
151 |
" <td>country</td>\n",
|
152 |
" <td>NaN</td>\n",
|
153 |
" <td>SFR</td>\n",
|
154 |
+
" <td>2018-01-31</td>\n",
|
|
|
155 |
" <td>NaN</td>\n",
|
156 |
+
" <td>254900.0</td>\n",
|
157 |
" <td>NaN</td>\n",
|
158 |
" <td>NaN</td>\n",
|
159 |
" <td>NaN</td>\n",
|
|
|
166 |
" <td>United States</td>\n",
|
167 |
" <td>country</td>\n",
|
168 |
" <td>NaN</td>\n",
|
169 |
+
" <td>SFR</td>\n",
|
170 |
+
" <td>2018-02-03</td>\n",
|
171 |
+
" <td>NaN</td>\n",
|
172 |
+
" <td>260000.0</td>\n",
|
173 |
+
" <td>259700.0</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",
|
|
|
192 |
" <td>...</td>\n",
|
193 |
" </tr>\n",
|
194 |
" <tr>\n",
|
195 |
+
" <th>693656</th>\n",
|
196 |
" <td>845172</td>\n",
|
197 |
" <td>769</td>\n",
|
198 |
" <td>Winfield, KS</td>\n",
|
199 |
" <td>msa</td>\n",
|
200 |
" <td>KS</td>\n",
|
201 |
" <td>all homes</td>\n",
|
202 |
+
" <td>2023-12-16</td>\n",
|
203 |
+
" <td>NaN</td>\n",
|
204 |
+
" <td>133938.0</td>\n",
|
205 |
+
" <td>133938.0</td>\n",
|
206 |
" <td>NaN</td>\n",
|
|
|
207 |
" <td>NaN</td>\n",
|
|
|
208 |
" <td>NaN</td>\n",
|
|
|
209 |
" </tr>\n",
|
210 |
" <tr>\n",
|
211 |
+
" <th>693657</th>\n",
|
212 |
" <td>845172</td>\n",
|
213 |
" <td>769</td>\n",
|
214 |
" <td>Winfield, KS</td>\n",
|
215 |
" <td>msa</td>\n",
|
216 |
" <td>KS</td>\n",
|
217 |
+
" <td>all homes</td>\n",
|
218 |
+
" <td>2023-12-23</td>\n",
|
|
|
|
|
219 |
" <td>NaN</td>\n",
|
220 |
+
" <td>126463.0</td>\n",
|
221 |
+
" <td>126463.0</td>\n",
|
222 |
" <td>NaN</td>\n",
|
223 |
" <td>NaN</td>\n",
|
224 |
" <td>NaN</td>\n",
|
225 |
" </tr>\n",
|
226 |
" <tr>\n",
|
227 |
+
" <th>693658</th>\n",
|
228 |
" <td>845172</td>\n",
|
229 |
" <td>769</td>\n",
|
230 |
" <td>Winfield, KS</td>\n",
|
231 |
" <td>msa</td>\n",
|
232 |
" <td>KS</td>\n",
|
233 |
+
" <td>all homes</td>\n",
|
234 |
+
" <td>2023-12-30</td>\n",
|
|
|
|
|
235 |
" <td>NaN</td>\n",
|
236 |
+
" <td>123225.0</td>\n",
|
237 |
+
" <td>123225.0</td>\n",
|
238 |
" <td>NaN</td>\n",
|
239 |
" <td>NaN</td>\n",
|
240 |
" <td>NaN</td>\n",
|
241 |
" </tr>\n",
|
242 |
" <tr>\n",
|
243 |
+
" <th>693659</th>\n",
|
244 |
" <td>845172</td>\n",
|
245 |
" <td>769</td>\n",
|
246 |
" <td>Winfield, KS</td>\n",
|
247 |
" <td>msa</td>\n",
|
248 |
" <td>KS</td>\n",
|
249 |
" <td>all homes</td>\n",
|
250 |
+
" <td>2023-12-31</td>\n",
|
251 |
+
" <td>24.0</td>\n",
|
252 |
+
" <td>136233.0</td>\n",
|
253 |
+
" <td>136233.0</td>\n",
|
254 |
+
" <td>24.0</td>\n",
|
255 |
+
" <td>28.0</td>\n",
|
256 |
+
" <td>28.0</td>\n",
|
257 |
" </tr>\n",
|
258 |
" <tr>\n",
|
259 |
+
" <th>693660</th>\n",
|
260 |
" <td>845172</td>\n",
|
261 |
" <td>769</td>\n",
|
262 |
" <td>Winfield, KS</td>\n",
|
|
|
266 |
" <td>2024-01-06</td>\n",
|
267 |
" <td>NaN</td>\n",
|
268 |
" <td>121488.0</td>\n",
|
269 |
+
" <td>121488.0</td>\n",
|
270 |
" <td>NaN</td>\n",
|
271 |
" <td>NaN</td>\n",
|
272 |
" <td>NaN</td>\n",
|
273 |
" </tr>\n",
|
274 |
" </tbody>\n",
|
275 |
"</table>\n",
|
276 |
+
"<p>693661 rows Γ 13 columns</p>\n",
|
277 |
"</div>"
|
278 |
],
|
279 |
"text/plain": [
|
280 |
+
" RegionID SizeRank RegionName RegionType StateName Home Type \\\n",
|
281 |
+
"0 102001 0 United States country NaN SFR \n",
|
282 |
+
"1 102001 0 United States country NaN SFR \n",
|
283 |
+
"2 102001 0 United States country NaN SFR \n",
|
284 |
+
"3 102001 0 United States country NaN SFR \n",
|
285 |
+
"4 102001 0 United States country NaN SFR \n",
|
286 |
+
"... ... ... ... ... ... ... \n",
|
287 |
+
"693656 845172 769 Winfield, KS msa KS all homes \n",
|
288 |
+
"693657 845172 769 Winfield, KS msa KS all homes \n",
|
289 |
+
"693658 845172 769 Winfield, KS msa KS all homes \n",
|
290 |
+
"693659 845172 769 Winfield, KS msa KS all homes \n",
|
291 |
+
"693660 845172 769 Winfield, KS msa KS all homes \n",
|
292 |
"\n",
|
293 |
+
" Date New Pending (Smoothed) Median Listing Price \\\n",
|
294 |
+
"0 2018-01-13 NaN 259000.0 \n",
|
295 |
+
"1 2018-01-20 NaN 259900.0 \n",
|
296 |
+
"2 2018-01-27 NaN 259900.0 \n",
|
297 |
+
"3 2018-01-31 NaN 254900.0 \n",
|
298 |
+
"4 2018-02-03 NaN 260000.0 \n",
|
299 |
+
"... ... ... ... \n",
|
300 |
+
"693656 2023-12-16 NaN 133938.0 \n",
|
301 |
+
"693657 2023-12-23 NaN 126463.0 \n",
|
302 |
+
"693658 2023-12-30 NaN 123225.0 \n",
|
303 |
+
"693659 2023-12-31 24.0 136233.0 \n",
|
304 |
+
"693660 2024-01-06 NaN 121488.0 \n",
|
305 |
"\n",
|
306 |
+
" Median Listing Price (Smoothed) New Pending New Listings \\\n",
|
307 |
+
"0 NaN NaN NaN \n",
|
308 |
+
"1 NaN NaN NaN \n",
|
309 |
+
"2 NaN NaN NaN \n",
|
310 |
+
"3 NaN NaN NaN \n",
|
311 |
+
"4 259700.0 NaN NaN \n",
|
312 |
+
"... ... ... ... \n",
|
313 |
+
"693656 133938.0 NaN NaN \n",
|
314 |
+
"693657 126463.0 NaN NaN \n",
|
315 |
+
"693658 123225.0 NaN NaN \n",
|
316 |
+
"693659 136233.0 24.0 28.0 \n",
|
317 |
+
"693660 121488.0 NaN NaN \n",
|
318 |
"\n",
|
319 |
+
" New Listings (Smoothed) \n",
|
320 |
+
"0 NaN \n",
|
321 |
+
"1 NaN \n",
|
322 |
+
"2 NaN \n",
|
323 |
+
"3 NaN \n",
|
324 |
+
"4 NaN \n",
|
325 |
+
"... ... \n",
|
326 |
+
"693656 NaN \n",
|
327 |
+
"693657 NaN \n",
|
328 |
+
"693658 NaN \n",
|
329 |
+
"693659 28.0 \n",
|
330 |
+
"693660 NaN \n",
|
331 |
"\n",
|
332 |
+
"[693661 rows x 13 columns]"
|
333 |
]
|
334 |
},
|
335 |
+
"execution_count": 5,
|
336 |
"metadata": {},
|
337 |
"output_type": "execute_result"
|
338 |
}
|
|
|
349 |
" \"Home Type\",\n",
|
350 |
"]\n",
|
351 |
"\n",
|
352 |
+
"data_frames = []\n",
|
353 |
"\n",
|
354 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
355 |
" if filename.endswith(\".csv\"):\n",
|
|
|
384 |
" else \"Median Listing Price (Smoothed)\"\n",
|
385 |
" ),\n",
|
386 |
" )\n",
|
387 |
+
" data_frames.append(cur_df)\n",
|
388 |
"\n",
|
389 |
" elif \"_new_listings_\" in filename:\n",
|
390 |
" cur_df = pd.melt(\n",
|
|
|
396 |
" \"New Listings\" if not smoothed else \"New Listings (Smoothed)\"\n",
|
397 |
" ),\n",
|
398 |
" )\n",
|
399 |
+
" data_frames.append(cur_df)\n",
|
400 |
"\n",
|
401 |
" elif \"new_pending\" in filename:\n",
|
402 |
" cur_df = pd.melt(\n",
|
|
|
406 |
" var_name=\"Date\",\n",
|
407 |
" value_name=\"New Pending\" if not smoothed else \"New Pending (Smoothed)\",\n",
|
408 |
" )\n",
|
409 |
+
" data_frames.append(cur_df)\n",
|
410 |
"\n",
|
411 |
"matching_cols = [\n",
|
412 |
" \"RegionID\",\n",
|
|
|
418 |
" \"Home Type\",\n",
|
419 |
"]\n",
|
420 |
"\n",
|
|
|
421 |
"\n",
|
422 |
+
"def get_combined_df(data_frames):\n",
|
423 |
+
" combined_df = None\n",
|
424 |
+
" if len(data_frames) > 1:\n",
|
425 |
+
" # iterate over dataframes and merge or concat\n",
|
426 |
+
" combined_df = data_frames[0]\n",
|
427 |
+
" for i in range(1, len(data_frames)):\n",
|
428 |
+
" cur_df = data_frames[i]\n",
|
429 |
+
" combined_df = pd.merge(\n",
|
430 |
+
" combined_df,\n",
|
431 |
+
" cur_df,\n",
|
432 |
+
" on=[\n",
|
433 |
+
" \"RegionID\",\n",
|
434 |
+
" \"SizeRank\",\n",
|
435 |
+
" \"RegionName\",\n",
|
436 |
+
" \"RegionType\",\n",
|
437 |
+
" \"StateName\",\n",
|
438 |
+
" \"Home Type\",\n",
|
439 |
+
" \"Date\",\n",
|
440 |
+
" ],\n",
|
441 |
+
" suffixes=(\"\", \"_\" + str(i)),\n",
|
442 |
+
" how=\"outer\",\n",
|
443 |
+
" )\n",
|
444 |
+
" elif len(data_frames) == 1:\n",
|
445 |
+
" combined_df = data_frames[0]\n",
|
446 |
+
"\n",
|
447 |
+
" return combined_df\n",
|
448 |
+
"\n",
|
449 |
+
"\n",
|
450 |
+
"combined_df = get_combined_df(data_frames)\n",
|
451 |
"\n",
|
452 |
"\n",
|
453 |
+
"# iterate over rows of combined df and coalesce column values across columns that start with \"Median Sale Price\"\n",
|
454 |
+
"columns_to_coalesce = [\n",
|
455 |
+
" \"Median Listing Price\",\n",
|
456 |
+
" \"Median Listing Price (Smoothed)\",\n",
|
457 |
+
" \"New Listings\",\n",
|
458 |
+
" \"New Listings (Smoothed)\",\n",
|
459 |
+
" \"New Pending (Smoothed)\",\n",
|
460 |
+
" \"New Pending\",\n",
|
461 |
+
"]\n",
|
462 |
+
"\n",
|
463 |
+
"for index, row in combined_df.iterrows():\n",
|
464 |
+
" for col in combined_df.columns:\n",
|
465 |
+
" for column_to_coalesce in columns_to_coalesce:\n",
|
466 |
+
" if column_to_coalesce in col and \"_\" in col:\n",
|
467 |
+
" if not pd.isna(row[col]):\n",
|
468 |
+
" combined_df.at[index, column_to_coalesce] = row[col]\n",
|
469 |
+
"\n",
|
470 |
+
"# remove columns with underscores\n",
|
471 |
+
"combined_df = combined_df[[col for col in combined_df.columns if \"_\" not in col]]\n",
|
472 |
+
"\n",
|
473 |
"combined_df"
|
474 |
]
|
475 |
},
|
476 |
{
|
477 |
"cell_type": "code",
|
478 |
+
"execution_count": 6,
|
479 |
"metadata": {},
|
480 |
"outputs": [
|
481 |
{
|
|
|
506 |
" <th>State</th>\n",
|
507 |
" <th>Home Type</th>\n",
|
508 |
" <th>Date</th>\n",
|
509 |
+
" <th>New Pending (Smoothed)</th>\n",
|
510 |
" <th>Median Listing Price</th>\n",
|
511 |
" <th>Median Listing Price (Smoothed)</th>\n",
|
512 |
+
" <th>New Pending</th>\n",
|
513 |
" <th>New Listings</th>\n",
|
514 |
" <th>New Listings (Smoothed)</th>\n",
|
|
|
|
|
515 |
" </tr>\n",
|
516 |
" </thead>\n",
|
517 |
" <tbody>\n",
|
|
|
522 |
" <td>United States</td>\n",
|
523 |
" <td>country</td>\n",
|
524 |
" <td>NaN</td>\n",
|
525 |
+
" <td>SFR</td>\n",
|
526 |
+
" <td>2018-01-13</td>\n",
|
527 |
" <td>NaN</td>\n",
|
528 |
+
" <td>259000.0</td>\n",
|
529 |
" <td>NaN</td>\n",
|
530 |
" <td>NaN</td>\n",
|
531 |
" <td>NaN</td>\n",
|
532 |
" <td>NaN</td>\n",
|
|
|
533 |
" </tr>\n",
|
534 |
" <tr>\n",
|
535 |
" <th>1</th>\n",
|
|
|
539 |
" <td>country</td>\n",
|
540 |
" <td>NaN</td>\n",
|
541 |
" <td>SFR</td>\n",
|
542 |
+
" <td>2018-01-20</td>\n",
|
|
|
543 |
" <td>NaN</td>\n",
|
544 |
+
" <td>259900.0</td>\n",
|
545 |
" <td>NaN</td>\n",
|
546 |
" <td>NaN</td>\n",
|
547 |
" <td>NaN</td>\n",
|
|
|
554 |
" <td>United States</td>\n",
|
555 |
" <td>country</td>\n",
|
556 |
" <td>NaN</td>\n",
|
557 |
+
" <td>SFR</td>\n",
|
558 |
+
" <td>2018-01-27</td>\n",
|
559 |
+
" <td>NaN</td>\n",
|
560 |
" <td>259900.0</td>\n",
|
561 |
" <td>NaN</td>\n",
|
|
|
562 |
" <td>NaN</td>\n",
|
563 |
" <td>NaN</td>\n",
|
564 |
+
" <td>NaN</td>\n",
|
565 |
" </tr>\n",
|
566 |
" <tr>\n",
|
567 |
" <th>3</th>\n",
|
|
|
571 |
" <td>country</td>\n",
|
572 |
" <td>NaN</td>\n",
|
573 |
" <td>SFR</td>\n",
|
574 |
+
" <td>2018-01-31</td>\n",
|
|
|
575 |
" <td>NaN</td>\n",
|
576 |
+
" <td>254900.0</td>\n",
|
577 |
" <td>NaN</td>\n",
|
578 |
" <td>NaN</td>\n",
|
579 |
" <td>NaN</td>\n",
|
|
|
586 |
" <td>United States</td>\n",
|
587 |
" <td>country</td>\n",
|
588 |
" <td>NaN</td>\n",
|
589 |
+
" <td>SFR</td>\n",
|
590 |
+
" <td>2018-02-03</td>\n",
|
591 |
+
" <td>NaN</td>\n",
|
592 |
+
" <td>260000.0</td>\n",
|
593 |
+
" <td>259700.0</td>\n",
|
594 |
" <td>NaN</td>\n",
|
|
|
595 |
" <td>NaN</td>\n",
|
596 |
" <td>NaN</td>\n",
|
|
|
597 |
" </tr>\n",
|
598 |
" <tr>\n",
|
599 |
" <th>...</th>\n",
|
|
|
612 |
" <td>...</td>\n",
|
613 |
" </tr>\n",
|
614 |
" <tr>\n",
|
615 |
+
" <th>693656</th>\n",
|
616 |
" <td>845172</td>\n",
|
617 |
" <td>769</td>\n",
|
618 |
" <td>Winfield, KS</td>\n",
|
619 |
" <td>msa</td>\n",
|
620 |
" <td>KS</td>\n",
|
621 |
" <td>all homes</td>\n",
|
622 |
+
" <td>2023-12-16</td>\n",
|
623 |
+
" <td>NaN</td>\n",
|
624 |
+
" <td>133938.0</td>\n",
|
625 |
+
" <td>133938.0</td>\n",
|
626 |
" <td>NaN</td>\n",
|
|
|
627 |
" <td>NaN</td>\n",
|
|
|
628 |
" <td>NaN</td>\n",
|
|
|
629 |
" </tr>\n",
|
630 |
" <tr>\n",
|
631 |
+
" <th>693657</th>\n",
|
632 |
" <td>845172</td>\n",
|
633 |
" <td>769</td>\n",
|
634 |
" <td>Winfield, KS</td>\n",
|
635 |
" <td>msa</td>\n",
|
636 |
" <td>KS</td>\n",
|
637 |
+
" <td>all homes</td>\n",
|
638 |
+
" <td>2023-12-23</td>\n",
|
|
|
|
|
639 |
" <td>NaN</td>\n",
|
640 |
+
" <td>126463.0</td>\n",
|
641 |
+
" <td>126463.0</td>\n",
|
642 |
" <td>NaN</td>\n",
|
643 |
" <td>NaN</td>\n",
|
644 |
" <td>NaN</td>\n",
|
645 |
" </tr>\n",
|
646 |
" <tr>\n",
|
647 |
+
" <th>693658</th>\n",
|
648 |
" <td>845172</td>\n",
|
649 |
" <td>769</td>\n",
|
650 |
" <td>Winfield, KS</td>\n",
|
651 |
" <td>msa</td>\n",
|
652 |
" <td>KS</td>\n",
|
653 |
+
" <td>all homes</td>\n",
|
654 |
+
" <td>2023-12-30</td>\n",
|
|
|
|
|
655 |
" <td>NaN</td>\n",
|
656 |
+
" <td>123225.0</td>\n",
|
657 |
+
" <td>123225.0</td>\n",
|
658 |
" <td>NaN</td>\n",
|
659 |
" <td>NaN</td>\n",
|
660 |
" <td>NaN</td>\n",
|
661 |
" </tr>\n",
|
662 |
" <tr>\n",
|
663 |
+
" <th>693659</th>\n",
|
664 |
" <td>845172</td>\n",
|
665 |
" <td>769</td>\n",
|
666 |
" <td>Winfield, KS</td>\n",
|
667 |
" <td>msa</td>\n",
|
668 |
" <td>KS</td>\n",
|
669 |
" <td>all homes</td>\n",
|
670 |
+
" <td>2023-12-31</td>\n",
|
671 |
+
" <td>24.0</td>\n",
|
672 |
+
" <td>136233.0</td>\n",
|
673 |
+
" <td>136233.0</td>\n",
|
674 |
+
" <td>24.0</td>\n",
|
675 |
+
" <td>28.0</td>\n",
|
676 |
+
" <td>28.0</td>\n",
|
677 |
" </tr>\n",
|
678 |
" <tr>\n",
|
679 |
+
" <th>693660</th>\n",
|
680 |
" <td>845172</td>\n",
|
681 |
" <td>769</td>\n",
|
682 |
" <td>Winfield, KS</td>\n",
|
|
|
686 |
" <td>2024-01-06</td>\n",
|
687 |
" <td>NaN</td>\n",
|
688 |
" <td>121488.0</td>\n",
|
689 |
+
" <td>121488.0</td>\n",
|
690 |
" <td>NaN</td>\n",
|
691 |
" <td>NaN</td>\n",
|
692 |
" <td>NaN</td>\n",
|
693 |
" </tr>\n",
|
694 |
" </tbody>\n",
|
695 |
"</table>\n",
|
696 |
+
"<p>693661 rows Γ 13 columns</p>\n",
|
697 |
"</div>"
|
698 |
],
|
699 |
"text/plain": [
|
700 |
+
" Region ID Size Rank Region Region Type State Home Type \\\n",
|
701 |
+
"0 102001 0 United States country NaN SFR \n",
|
702 |
+
"1 102001 0 United States country NaN SFR \n",
|
703 |
+
"2 102001 0 United States country NaN SFR \n",
|
704 |
+
"3 102001 0 United States country NaN SFR \n",
|
705 |
+
"4 102001 0 United States country NaN SFR \n",
|
706 |
+
"... ... ... ... ... ... ... \n",
|
707 |
+
"693656 845172 769 Winfield, KS msa KS all homes \n",
|
708 |
+
"693657 845172 769 Winfield, KS msa KS all homes \n",
|
709 |
+
"693658 845172 769 Winfield, KS msa KS all homes \n",
|
710 |
+
"693659 845172 769 Winfield, KS msa KS all homes \n",
|
711 |
+
"693660 845172 769 Winfield, KS msa KS all homes \n",
|
712 |
"\n",
|
713 |
+
" Date New Pending (Smoothed) Median Listing Price \\\n",
|
714 |
+
"0 2018-01-13 NaN 259000.0 \n",
|
715 |
+
"1 2018-01-20 NaN 259900.0 \n",
|
716 |
+
"2 2018-01-27 NaN 259900.0 \n",
|
717 |
+
"3 2018-01-31 NaN 254900.0 \n",
|
718 |
+
"4 2018-02-03 NaN 260000.0 \n",
|
719 |
+
"... ... ... ... \n",
|
720 |
+
"693656 2023-12-16 NaN 133938.0 \n",
|
721 |
+
"693657 2023-12-23 NaN 126463.0 \n",
|
722 |
+
"693658 2023-12-30 NaN 123225.0 \n",
|
723 |
+
"693659 2023-12-31 24.0 136233.0 \n",
|
724 |
+
"693660 2024-01-06 NaN 121488.0 \n",
|
725 |
"\n",
|
726 |
+
" Median Listing Price (Smoothed) New Pending New Listings \\\n",
|
727 |
+
"0 NaN NaN NaN \n",
|
728 |
+
"1 NaN NaN NaN \n",
|
729 |
+
"2 NaN NaN NaN \n",
|
730 |
+
"3 NaN NaN NaN \n",
|
731 |
+
"4 259700.0 NaN NaN \n",
|
732 |
+
"... ... ... ... \n",
|
733 |
+
"693656 133938.0 NaN NaN \n",
|
734 |
+
"693657 126463.0 NaN NaN \n",
|
735 |
+
"693658 123225.0 NaN NaN \n",
|
736 |
+
"693659 136233.0 24.0 28.0 \n",
|
737 |
+
"693660 121488.0 NaN NaN \n",
|
738 |
"\n",
|
739 |
+
" New Listings (Smoothed) \n",
|
740 |
+
"0 NaN \n",
|
741 |
+
"1 NaN \n",
|
742 |
+
"2 NaN \n",
|
743 |
+
"3 NaN \n",
|
744 |
+
"4 NaN \n",
|
745 |
+
"... ... \n",
|
746 |
+
"693656 NaN \n",
|
747 |
+
"693657 NaN \n",
|
748 |
+
"693658 NaN \n",
|
749 |
+
"693659 28.0 \n",
|
750 |
+
"693660 NaN \n",
|
751 |
"\n",
|
752 |
+
"[693661 rows x 13 columns]"
|
753 |
]
|
754 |
},
|
755 |
+
"execution_count": 6,
|
756 |
"metadata": {},
|
757 |
"output_type": "execute_result"
|
758 |
}
|
|
|
774 |
},
|
775 |
{
|
776 |
"cell_type": "code",
|
777 |
+
"execution_count": 7,
|
778 |
"metadata": {},
|
779 |
"outputs": [],
|
780 |
"source": [
|
processors/new_constructions.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
@@ -12,7 +12,7 @@
|
|
12 |
},
|
13 |
{
|
14 |
"cell_type": "code",
|
15 |
-
"execution_count":
|
16 |
"metadata": {},
|
17 |
"outputs": [],
|
18 |
"source": [
|
@@ -25,7 +25,7 @@
|
|
25 |
},
|
26 |
{
|
27 |
"cell_type": "code",
|
28 |
-
"execution_count":
|
29 |
"metadata": {},
|
30 |
"outputs": [
|
31 |
{
|
@@ -71,9 +71,9 @@
|
|
71 |
" <th>StateName</th>\n",
|
72 |
" <th>Home Type</th>\n",
|
73 |
" <th>Date</th>\n",
|
|
|
74 |
" <th>Median Sale Price per Sqft</th>\n",
|
75 |
" <th>Median Sale Price</th>\n",
|
76 |
-
" <th>Sales Count</th>\n",
|
77 |
" </tr>\n",
|
78 |
" </thead>\n",
|
79 |
" <tbody>\n",
|
@@ -86,9 +86,9 @@
|
|
86 |
" <td>NaN</td>\n",
|
87 |
" <td>SFR</td>\n",
|
88 |
" <td>2018-01-31</td>\n",
|
|
|
89 |
" <td>137.412316</td>\n",
|
90 |
" <td>309000.0</td>\n",
|
91 |
-
" <td>33940.0</td>\n",
|
92 |
" </tr>\n",
|
93 |
" <tr>\n",
|
94 |
" <th>1</th>\n",
|
@@ -97,11 +97,11 @@
|
|
97 |
" <td>United States</td>\n",
|
98 |
" <td>country</td>\n",
|
99 |
" <td>NaN</td>\n",
|
100 |
-
" <td>
|
101 |
-
" <td>2018-
|
102 |
-
" <td>
|
103 |
-
" <td>
|
104 |
-
" <td>
|
105 |
" </tr>\n",
|
106 |
" <tr>\n",
|
107 |
" <th>2</th>\n",
|
@@ -110,11 +110,11 @@
|
|
110 |
" <td>United States</td>\n",
|
111 |
" <td>country</td>\n",
|
112 |
" <td>NaN</td>\n",
|
113 |
-
" <td>
|
114 |
-
" <td>2018-
|
115 |
-
" <td>
|
116 |
-
" <td>
|
117 |
-
" <td>
|
118 |
" </tr>\n",
|
119 |
" <tr>\n",
|
120 |
" <th>3</th>\n",
|
@@ -124,10 +124,10 @@
|
|
124 |
" <td>country</td>\n",
|
125 |
" <td>NaN</td>\n",
|
126 |
" <td>SFR</td>\n",
|
127 |
-
" <td>2018-
|
128 |
-
" <td>
|
129 |
-
" <td>
|
130 |
-
" <td>
|
131 |
" </tr>\n",
|
132 |
" <tr>\n",
|
133 |
" <th>4</th>\n",
|
@@ -136,11 +136,11 @@
|
|
136 |
" <td>United States</td>\n",
|
137 |
" <td>country</td>\n",
|
138 |
" <td>NaN</td>\n",
|
139 |
-
" <td>
|
140 |
-
" <td>2018-
|
141 |
-
" <td>
|
142 |
-
" <td>
|
143 |
-
" <td>
|
144 |
" </tr>\n",
|
145 |
" <tr>\n",
|
146 |
" <th>...</th>\n",
|
@@ -163,10 +163,10 @@
|
|
163 |
" <td>msa</td>\n",
|
164 |
" <td>TX</td>\n",
|
165 |
" <td>all homes</td>\n",
|
166 |
-
" <td>2023-
|
|
|
167 |
" <td>NaN</td>\n",
|
168 |
" <td>NaN</td>\n",
|
169 |
-
" <td>26.0</td>\n",
|
170 |
" </tr>\n",
|
171 |
" <tr>\n",
|
172 |
" <th>49483</th>\n",
|
@@ -175,11 +175,11 @@
|
|
175 |
" <td>Granbury, TX</td>\n",
|
176 |
" <td>msa</td>\n",
|
177 |
" <td>TX</td>\n",
|
178 |
-
" <td>
|
179 |
-
" <td>2023-
|
|
|
180 |
" <td>NaN</td>\n",
|
181 |
" <td>NaN</td>\n",
|
182 |
-
" <td>24.0</td>\n",
|
183 |
" </tr>\n",
|
184 |
" <tr>\n",
|
185 |
" <th>49484</th>\n",
|
@@ -189,10 +189,10 @@
|
|
189 |
" <td>msa</td>\n",
|
190 |
" <td>TX</td>\n",
|
191 |
" <td>all homes</td>\n",
|
192 |
-
" <td>2023-
|
|
|
193 |
" <td>NaN</td>\n",
|
194 |
" <td>NaN</td>\n",
|
195 |
-
" <td>24.0</td>\n",
|
196 |
" </tr>\n",
|
197 |
" <tr>\n",
|
198 |
" <th>49485</th>\n",
|
@@ -201,11 +201,11 @@
|
|
201 |
" <td>Granbury, TX</td>\n",
|
202 |
" <td>msa</td>\n",
|
203 |
" <td>TX</td>\n",
|
204 |
-
" <td>
|
205 |
-
" <td>2023-
|
|
|
206 |
" <td>NaN</td>\n",
|
207 |
" <td>NaN</td>\n",
|
208 |
-
" <td>16.0</td>\n",
|
209 |
" </tr>\n",
|
210 |
" <tr>\n",
|
211 |
" <th>49486</th>\n",
|
@@ -216,9 +216,9 @@
|
|
216 |
" <td>TX</td>\n",
|
217 |
" <td>all homes</td>\n",
|
218 |
" <td>2023-11-30</td>\n",
|
|
|
219 |
" <td>NaN</td>\n",
|
220 |
" <td>NaN</td>\n",
|
221 |
-
" <td>16.0</td>\n",
|
222 |
" </tr>\n",
|
223 |
" </tbody>\n",
|
224 |
"</table>\n",
|
@@ -226,49 +226,36 @@
|
|
226 |
"</div>"
|
227 |
],
|
228 |
"text/plain": [
|
229 |
-
" RegionID SizeRank RegionName RegionType StateName \\\n",
|
230 |
-
"0 102001 0 United States country NaN \n",
|
231 |
-
"1 102001 0 United States country NaN \n",
|
232 |
-
"2 102001 0 United States country NaN \n",
|
233 |
-
"3 102001 0 United States country NaN \n",
|
234 |
-
"4 102001 0 United States country NaN \n",
|
235 |
-
"... ... ... ... ... ... \n",
|
236 |
-
"49482 845162 535 Granbury, TX msa TX \n",
|
237 |
-
"49483 845162 535 Granbury, TX msa TX \n",
|
238 |
-
"49484 845162 535 Granbury, TX msa TX \n",
|
239 |
-
"49485 845162 535 Granbury, TX msa TX \n",
|
240 |
-
"49486 845162 535 Granbury, TX msa TX \n",
|
241 |
-
"\n",
|
242 |
-
" Home Type Date Median Sale Price per Sqft \\\n",
|
243 |
-
"0 SFR 2018-01-31 137.412316 \n",
|
244 |
-
"1 all homes 2018-01-31 140.504620 \n",
|
245 |
-
"2 condo/co-op only 2018-01-31 238.300000 \n",
|
246 |
-
"3 SFR 2018-02-28 137.199170 \n",
|
247 |
-
"4 all homes 2018-02-28 140.304966 \n",
|
248 |
-
"... ... ... ... \n",
|
249 |
-
"49482 all homes 2023-09-30 NaN \n",
|
250 |
-
"49483 SFR 2023-10-31 NaN \n",
|
251 |
-
"49484 all homes 2023-10-31 NaN \n",
|
252 |
-
"49485 SFR 2023-11-30 NaN \n",
|
253 |
-
"49486 all homes 2023-11-30 NaN \n",
|
254 |
"\n",
|
255 |
-
"
|
256 |
-
"0
|
257 |
-
"1
|
258 |
-
"2
|
259 |
-
"3
|
260 |
-
"4
|
261 |
-
"...
|
262 |
-
"49482
|
263 |
-
"49483
|
264 |
-
"49484
|
265 |
-
"49485
|
266 |
-
"49486
|
267 |
"\n",
|
268 |
"[49487 rows x 10 columns]"
|
269 |
]
|
270 |
},
|
271 |
-
"execution_count":
|
272 |
"metadata": {},
|
273 |
"output_type": "execute_result"
|
274 |
}
|
@@ -285,7 +272,7 @@
|
|
285 |
" \"Home Type\",\n",
|
286 |
"]\n",
|
287 |
"\n",
|
288 |
-
"
|
289 |
"\n",
|
290 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
291 |
" if filename.endswith(\".csv\"):\n",
|
@@ -310,7 +297,7 @@
|
|
310 |
" var_name=\"Date\",\n",
|
311 |
" value_name=\"Median Sale Price per Sqft\",\n",
|
312 |
" )\n",
|
313 |
-
"
|
314 |
"\n",
|
315 |
" elif \"median_sale_price\" in filename:\n",
|
316 |
" cur_df = pd.melt(\n",
|
@@ -320,7 +307,7 @@
|
|
320 |
" var_name=\"Date\",\n",
|
321 |
" value_name=\"Median Sale Price\",\n",
|
322 |
" )\n",
|
323 |
-
"
|
324 |
"\n",
|
325 |
" elif \"sales_count\" in filename:\n",
|
326 |
" cur_df = pd.melt(\n",
|
@@ -330,37 +317,57 @@
|
|
330 |
" var_name=\"Date\",\n",
|
331 |
" value_name=\"Sales Count\",\n",
|
332 |
" )\n",
|
333 |
-
"
|
334 |
"\n",
|
335 |
"\n",
|
336 |
-
"
|
337 |
-
" \
|
338 |
-
"
|
339 |
-
"
|
340 |
-
"
|
341 |
-
"
|
342 |
-
"
|
343 |
-
"
|
344 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
"\n",
|
346 |
-
"
|
|
|
|
|
|
|
|
|
|
|
347 |
"\n",
|
348 |
-
"
|
349 |
-
"
|
350 |
-
" for batch in combined_batches[1:]:\n",
|
351 |
-
" combined_df = pd.merge(\n",
|
352 |
-
" combined_df,\n",
|
353 |
-
" batch,\n",
|
354 |
-
" on=matching_cols,\n",
|
355 |
-
" how=\"outer\",\n",
|
356 |
-
" )\n",
|
357 |
"\n",
|
358 |
"combined_df"
|
359 |
]
|
360 |
},
|
361 |
{
|
362 |
"cell_type": "code",
|
363 |
-
"execution_count":
|
364 |
"metadata": {},
|
365 |
"outputs": [
|
366 |
{
|
@@ -391,9 +398,9 @@
|
|
391 |
" <th>State</th>\n",
|
392 |
" <th>Home Type</th>\n",
|
393 |
" <th>Date</th>\n",
|
|
|
394 |
" <th>Median Sale Price per Sqft</th>\n",
|
395 |
" <th>Median Sale Price</th>\n",
|
396 |
-
" <th>Sales Count</th>\n",
|
397 |
" </tr>\n",
|
398 |
" </thead>\n",
|
399 |
" <tbody>\n",
|
@@ -406,9 +413,9 @@
|
|
406 |
" <td>NaN</td>\n",
|
407 |
" <td>SFR</td>\n",
|
408 |
" <td>2018-01-31</td>\n",
|
|
|
409 |
" <td>137.412316</td>\n",
|
410 |
" <td>309000.0</td>\n",
|
411 |
-
" <td>33940.0</td>\n",
|
412 |
" </tr>\n",
|
413 |
" <tr>\n",
|
414 |
" <th>1</th>\n",
|
@@ -417,11 +424,11 @@
|
|
417 |
" <td>United States</td>\n",
|
418 |
" <td>country</td>\n",
|
419 |
" <td>NaN</td>\n",
|
420 |
-
" <td>
|
421 |
-
" <td>2018-
|
422 |
-
" <td>
|
423 |
-
" <td>
|
424 |
-
" <td>
|
425 |
" </tr>\n",
|
426 |
" <tr>\n",
|
427 |
" <th>2</th>\n",
|
@@ -430,11 +437,11 @@
|
|
430 |
" <td>United States</td>\n",
|
431 |
" <td>country</td>\n",
|
432 |
" <td>NaN</td>\n",
|
433 |
-
" <td>
|
434 |
-
" <td>2018-
|
435 |
-
" <td>
|
436 |
-
" <td>
|
437 |
-
" <td>
|
438 |
" </tr>\n",
|
439 |
" <tr>\n",
|
440 |
" <th>3</th>\n",
|
@@ -444,10 +451,10 @@
|
|
444 |
" <td>country</td>\n",
|
445 |
" <td>NaN</td>\n",
|
446 |
" <td>SFR</td>\n",
|
447 |
-
" <td>2018-
|
448 |
-
" <td>
|
449 |
-
" <td>
|
450 |
-
" <td>
|
451 |
" </tr>\n",
|
452 |
" <tr>\n",
|
453 |
" <th>4</th>\n",
|
@@ -456,11 +463,11 @@
|
|
456 |
" <td>United States</td>\n",
|
457 |
" <td>country</td>\n",
|
458 |
" <td>NaN</td>\n",
|
459 |
-
" <td>
|
460 |
-
" <td>2018-
|
461 |
-
" <td>
|
462 |
-
" <td>
|
463 |
-
" <td>
|
464 |
" </tr>\n",
|
465 |
" <tr>\n",
|
466 |
" <th>...</th>\n",
|
@@ -483,10 +490,10 @@
|
|
483 |
" <td>msa</td>\n",
|
484 |
" <td>TX</td>\n",
|
485 |
" <td>all homes</td>\n",
|
486 |
-
" <td>2023-
|
|
|
487 |
" <td>NaN</td>\n",
|
488 |
" <td>NaN</td>\n",
|
489 |
-
" <td>26.0</td>\n",
|
490 |
" </tr>\n",
|
491 |
" <tr>\n",
|
492 |
" <th>49483</th>\n",
|
@@ -495,11 +502,11 @@
|
|
495 |
" <td>Granbury, TX</td>\n",
|
496 |
" <td>msa</td>\n",
|
497 |
" <td>TX</td>\n",
|
498 |
-
" <td>
|
499 |
-
" <td>2023-
|
|
|
500 |
" <td>NaN</td>\n",
|
501 |
" <td>NaN</td>\n",
|
502 |
-
" <td>24.0</td>\n",
|
503 |
" </tr>\n",
|
504 |
" <tr>\n",
|
505 |
" <th>49484</th>\n",
|
@@ -509,10 +516,10 @@
|
|
509 |
" <td>msa</td>\n",
|
510 |
" <td>TX</td>\n",
|
511 |
" <td>all homes</td>\n",
|
512 |
-
" <td>2023-
|
|
|
513 |
" <td>NaN</td>\n",
|
514 |
" <td>NaN</td>\n",
|
515 |
-
" <td>24.0</td>\n",
|
516 |
" </tr>\n",
|
517 |
" <tr>\n",
|
518 |
" <th>49485</th>\n",
|
@@ -521,11 +528,11 @@
|
|
521 |
" <td>Granbury, TX</td>\n",
|
522 |
" <td>msa</td>\n",
|
523 |
" <td>TX</td>\n",
|
524 |
-
" <td>
|
525 |
-
" <td>2023-
|
|
|
526 |
" <td>NaN</td>\n",
|
527 |
" <td>NaN</td>\n",
|
528 |
-
" <td>16.0</td>\n",
|
529 |
" </tr>\n",
|
530 |
" <tr>\n",
|
531 |
" <th>49486</th>\n",
|
@@ -536,9 +543,9 @@
|
|
536 |
" <td>TX</td>\n",
|
537 |
" <td>all homes</td>\n",
|
538 |
" <td>2023-11-30</td>\n",
|
|
|
539 |
" <td>NaN</td>\n",
|
540 |
" <td>NaN</td>\n",
|
541 |
-
" <td>16.0</td>\n",
|
542 |
" </tr>\n",
|
543 |
" </tbody>\n",
|
544 |
"</table>\n",
|
@@ -546,49 +553,36 @@
|
|
546 |
"</div>"
|
547 |
],
|
548 |
"text/plain": [
|
549 |
-
" Region ID Size Rank Region Region Type State \\\n",
|
550 |
-
"0 102001 0 United States country NaN \n",
|
551 |
-
"1 102001 0 United States country NaN \n",
|
552 |
-
"2 102001 0 United States country NaN \n",
|
553 |
-
"3 102001 0 United States country NaN \n",
|
554 |
-
"4 102001 0 United States country NaN \n",
|
555 |
-
"... ... ... ... ... ... \n",
|
556 |
-
"49482 845162 535 Granbury, TX msa TX \n",
|
557 |
-
"49483 845162 535 Granbury, TX msa TX \n",
|
558 |
-
"49484 845162 535 Granbury, TX msa TX \n",
|
559 |
-
"49485 845162 535 Granbury, TX msa TX \n",
|
560 |
-
"49486 845162 535 Granbury, TX msa TX \n",
|
561 |
-
"\n",
|
562 |
-
" Home Type Date Median Sale Price per Sqft \\\n",
|
563 |
-
"0 SFR 2018-01-31 137.412316 \n",
|
564 |
-
"1 all homes 2018-01-31 140.504620 \n",
|
565 |
-
"2 condo/co-op only 2018-01-31 238.300000 \n",
|
566 |
-
"3 SFR 2018-02-28 137.199170 \n",
|
567 |
-
"4 all homes 2018-02-28 140.304966 \n",
|
568 |
-
"... ... ... ... \n",
|
569 |
-
"49482 all homes 2023-09-30 NaN \n",
|
570 |
-
"49483 SFR 2023-10-31 NaN \n",
|
571 |
-
"49484 all homes 2023-10-31 NaN \n",
|
572 |
-
"49485 SFR 2023-11-30 NaN \n",
|
573 |
-
"49486 all homes 2023-11-30 NaN \n",
|
574 |
"\n",
|
575 |
-
"
|
576 |
-
"0
|
577 |
-
"1
|
578 |
-
"2
|
579 |
-
"3
|
580 |
-
"4
|
581 |
-
"...
|
582 |
-
"49482
|
583 |
-
"49483
|
584 |
-
"49484
|
585 |
-
"49485
|
586 |
-
"49486
|
587 |
"\n",
|
588 |
"[49487 rows x 10 columns]"
|
589 |
]
|
590 |
},
|
591 |
-
"execution_count":
|
592 |
"metadata": {},
|
593 |
"output_type": "execute_result"
|
594 |
}
|
@@ -605,12 +599,12 @@
|
|
605 |
" }\n",
|
606 |
")\n",
|
607 |
"\n",
|
608 |
-
"final_df"
|
609 |
]
|
610 |
},
|
611 |
{
|
612 |
"cell_type": "code",
|
613 |
-
"execution_count":
|
614 |
"metadata": {},
|
615 |
"outputs": [],
|
616 |
"source": [
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
|
|
12 |
},
|
13 |
{
|
14 |
"cell_type": "code",
|
15 |
+
"execution_count": 3,
|
16 |
"metadata": {},
|
17 |
"outputs": [],
|
18 |
"source": [
|
|
|
25 |
},
|
26 |
{
|
27 |
"cell_type": "code",
|
28 |
+
"execution_count": 38,
|
29 |
"metadata": {},
|
30 |
"outputs": [
|
31 |
{
|
|
|
71 |
" <th>StateName</th>\n",
|
72 |
" <th>Home Type</th>\n",
|
73 |
" <th>Date</th>\n",
|
74 |
+
" <th>Sales Count</th>\n",
|
75 |
" <th>Median Sale Price per Sqft</th>\n",
|
76 |
" <th>Median Sale Price</th>\n",
|
|
|
77 |
" </tr>\n",
|
78 |
" </thead>\n",
|
79 |
" <tbody>\n",
|
|
|
86 |
" <td>NaN</td>\n",
|
87 |
" <td>SFR</td>\n",
|
88 |
" <td>2018-01-31</td>\n",
|
89 |
+
" <td>33940.0</td>\n",
|
90 |
" <td>137.412316</td>\n",
|
91 |
" <td>309000.0</td>\n",
|
|
|
92 |
" </tr>\n",
|
93 |
" <tr>\n",
|
94 |
" <th>1</th>\n",
|
|
|
97 |
" <td>United States</td>\n",
|
98 |
" <td>country</td>\n",
|
99 |
" <td>NaN</td>\n",
|
100 |
+
" <td>SFR</td>\n",
|
101 |
+
" <td>2018-02-28</td>\n",
|
102 |
+
" <td>33304.0</td>\n",
|
103 |
+
" <td>137.199170</td>\n",
|
104 |
+
" <td>309072.5</td>\n",
|
105 |
" </tr>\n",
|
106 |
" <tr>\n",
|
107 |
" <th>2</th>\n",
|
|
|
110 |
" <td>United States</td>\n",
|
111 |
" <td>country</td>\n",
|
112 |
" <td>NaN</td>\n",
|
113 |
+
" <td>SFR</td>\n",
|
114 |
+
" <td>2018-03-31</td>\n",
|
115 |
+
" <td>42641.0</td>\n",
|
116 |
+
" <td>139.520863</td>\n",
|
117 |
+
" <td>315488.0</td>\n",
|
118 |
" </tr>\n",
|
119 |
" <tr>\n",
|
120 |
" <th>3</th>\n",
|
|
|
124 |
" <td>country</td>\n",
|
125 |
" <td>NaN</td>\n",
|
126 |
" <td>SFR</td>\n",
|
127 |
+
" <td>2018-04-30</td>\n",
|
128 |
+
" <td>37588.0</td>\n",
|
129 |
+
" <td>139.778110</td>\n",
|
130 |
+
" <td>314990.0</td>\n",
|
131 |
" </tr>\n",
|
132 |
" <tr>\n",
|
133 |
" <th>4</th>\n",
|
|
|
136 |
" <td>United States</td>\n",
|
137 |
" <td>country</td>\n",
|
138 |
" <td>NaN</td>\n",
|
139 |
+
" <td>SFR</td>\n",
|
140 |
+
" <td>2018-05-31</td>\n",
|
141 |
+
" <td>39933.0</td>\n",
|
142 |
+
" <td>143.317968</td>\n",
|
143 |
+
" <td>324500.0</td>\n",
|
144 |
" </tr>\n",
|
145 |
" <tr>\n",
|
146 |
" <th>...</th>\n",
|
|
|
163 |
" <td>msa</td>\n",
|
164 |
" <td>TX</td>\n",
|
165 |
" <td>all homes</td>\n",
|
166 |
+
" <td>2023-07-31</td>\n",
|
167 |
+
" <td>31.0</td>\n",
|
168 |
" <td>NaN</td>\n",
|
169 |
" <td>NaN</td>\n",
|
|
|
170 |
" </tr>\n",
|
171 |
" <tr>\n",
|
172 |
" <th>49483</th>\n",
|
|
|
175 |
" <td>Granbury, TX</td>\n",
|
176 |
" <td>msa</td>\n",
|
177 |
" <td>TX</td>\n",
|
178 |
+
" <td>all homes</td>\n",
|
179 |
+
" <td>2023-08-31</td>\n",
|
180 |
+
" <td>33.0</td>\n",
|
181 |
" <td>NaN</td>\n",
|
182 |
" <td>NaN</td>\n",
|
|
|
183 |
" </tr>\n",
|
184 |
" <tr>\n",
|
185 |
" <th>49484</th>\n",
|
|
|
189 |
" <td>msa</td>\n",
|
190 |
" <td>TX</td>\n",
|
191 |
" <td>all homes</td>\n",
|
192 |
+
" <td>2023-09-30</td>\n",
|
193 |
+
" <td>26.0</td>\n",
|
194 |
" <td>NaN</td>\n",
|
195 |
" <td>NaN</td>\n",
|
|
|
196 |
" </tr>\n",
|
197 |
" <tr>\n",
|
198 |
" <th>49485</th>\n",
|
|
|
201 |
" <td>Granbury, TX</td>\n",
|
202 |
" <td>msa</td>\n",
|
203 |
" <td>TX</td>\n",
|
204 |
+
" <td>all homes</td>\n",
|
205 |
+
" <td>2023-10-31</td>\n",
|
206 |
+
" <td>24.0</td>\n",
|
207 |
" <td>NaN</td>\n",
|
208 |
" <td>NaN</td>\n",
|
|
|
209 |
" </tr>\n",
|
210 |
" <tr>\n",
|
211 |
" <th>49486</th>\n",
|
|
|
216 |
" <td>TX</td>\n",
|
217 |
" <td>all homes</td>\n",
|
218 |
" <td>2023-11-30</td>\n",
|
219 |
+
" <td>16.0</td>\n",
|
220 |
" <td>NaN</td>\n",
|
221 |
" <td>NaN</td>\n",
|
|
|
222 |
" </tr>\n",
|
223 |
" </tbody>\n",
|
224 |
"</table>\n",
|
|
|
226 |
"</div>"
|
227 |
],
|
228 |
"text/plain": [
|
229 |
+
" RegionID SizeRank RegionName RegionType StateName Home Type \\\n",
|
230 |
+
"0 102001 0 United States country NaN SFR \n",
|
231 |
+
"1 102001 0 United States country NaN SFR \n",
|
232 |
+
"2 102001 0 United States country NaN SFR \n",
|
233 |
+
"3 102001 0 United States country NaN SFR \n",
|
234 |
+
"4 102001 0 United States country NaN SFR \n",
|
235 |
+
"... ... ... ... ... ... ... \n",
|
236 |
+
"49482 845162 535 Granbury, TX msa TX all homes \n",
|
237 |
+
"49483 845162 535 Granbury, TX msa TX all homes \n",
|
238 |
+
"49484 845162 535 Granbury, TX msa TX all homes \n",
|
239 |
+
"49485 845162 535 Granbury, TX msa TX all homes \n",
|
240 |
+
"49486 845162 535 Granbury, TX msa TX all homes \n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
"\n",
|
242 |
+
" Date Sales Count Median Sale Price per Sqft Median Sale Price \n",
|
243 |
+
"0 2018-01-31 33940.0 137.412316 309000.0 \n",
|
244 |
+
"1 2018-02-28 33304.0 137.199170 309072.5 \n",
|
245 |
+
"2 2018-03-31 42641.0 139.520863 315488.0 \n",
|
246 |
+
"3 2018-04-30 37588.0 139.778110 314990.0 \n",
|
247 |
+
"4 2018-05-31 39933.0 143.317968 324500.0 \n",
|
248 |
+
"... ... ... ... ... \n",
|
249 |
+
"49482 2023-07-31 31.0 NaN NaN \n",
|
250 |
+
"49483 2023-08-31 33.0 NaN NaN \n",
|
251 |
+
"49484 2023-09-30 26.0 NaN NaN \n",
|
252 |
+
"49485 2023-10-31 24.0 NaN NaN \n",
|
253 |
+
"49486 2023-11-30 16.0 NaN NaN \n",
|
254 |
"\n",
|
255 |
"[49487 rows x 10 columns]"
|
256 |
]
|
257 |
},
|
258 |
+
"execution_count": 38,
|
259 |
"metadata": {},
|
260 |
"output_type": "execute_result"
|
261 |
}
|
|
|
272 |
" \"Home Type\",\n",
|
273 |
"]\n",
|
274 |
"\n",
|
275 |
+
"data_frames = []\n",
|
276 |
"\n",
|
277 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
278 |
" if filename.endswith(\".csv\"):\n",
|
|
|
297 |
" var_name=\"Date\",\n",
|
298 |
" value_name=\"Median Sale Price per Sqft\",\n",
|
299 |
" )\n",
|
300 |
+
" data_frames.append(cur_df)\n",
|
301 |
"\n",
|
302 |
" elif \"median_sale_price\" in filename:\n",
|
303 |
" cur_df = pd.melt(\n",
|
|
|
307 |
" var_name=\"Date\",\n",
|
308 |
" value_name=\"Median Sale Price\",\n",
|
309 |
" )\n",
|
310 |
+
" data_frames.append(cur_df)\n",
|
311 |
"\n",
|
312 |
" elif \"sales_count\" in filename:\n",
|
313 |
" cur_df = pd.melt(\n",
|
|
|
317 |
" var_name=\"Date\",\n",
|
318 |
" value_name=\"Sales Count\",\n",
|
319 |
" )\n",
|
320 |
+
" data_frames.append(cur_df)\n",
|
321 |
"\n",
|
322 |
"\n",
|
323 |
+
"def get_combined_df(data_frames):\n",
|
324 |
+
" combined_df = None\n",
|
325 |
+
" if len(data_frames) > 1:\n",
|
326 |
+
" # iterate over dataframes and merge or concat\n",
|
327 |
+
" combined_df = data_frames[0]\n",
|
328 |
+
" for i in range(1, len(data_frames)):\n",
|
329 |
+
" cur_df = data_frames[i]\n",
|
330 |
+
" combined_df = pd.merge(\n",
|
331 |
+
" combined_df,\n",
|
332 |
+
" cur_df,\n",
|
333 |
+
" on=[\n",
|
334 |
+
" \"RegionID\",\n",
|
335 |
+
" \"SizeRank\",\n",
|
336 |
+
" \"RegionName\",\n",
|
337 |
+
" \"RegionType\",\n",
|
338 |
+
" \"StateName\",\n",
|
339 |
+
" \"Home Type\",\n",
|
340 |
+
" \"Date\",\n",
|
341 |
+
" ],\n",
|
342 |
+
" how=\"outer\",\n",
|
343 |
+
" suffixes=(\"\", \"_\" + str(i)),\n",
|
344 |
+
" )\n",
|
345 |
+
" elif len(data_frames) == 1:\n",
|
346 |
+
" combined_df = data_frames[0]\n",
|
347 |
+
"\n",
|
348 |
+
" return combined_df\n",
|
349 |
+
"\n",
|
350 |
+
"\n",
|
351 |
+
"combined_df = get_combined_df(data_frames)\n",
|
352 |
+
"# iterate over rows of combined df and coalesce column values across columns that start with \"Median Sale Price\"\n",
|
353 |
+
"columns_to_coalesce = [\"Sales Count\", \"Median Sale Price\", \"Median Sale Price per Sqft\"]\n",
|
354 |
"\n",
|
355 |
+
"for index, row in combined_df.iterrows():\n",
|
356 |
+
" for col in combined_df.columns:\n",
|
357 |
+
" for column_to_coalesce in columns_to_coalesce:\n",
|
358 |
+
" if column_to_coalesce in col and \"_\" in col:\n",
|
359 |
+
" if not pd.isna(row[col]):\n",
|
360 |
+
" combined_df.at[index, column_to_coalesce] = row[col]\n",
|
361 |
"\n",
|
362 |
+
"# remove columns with underscores\n",
|
363 |
+
"combined_df = combined_df[[col for col in combined_df.columns if \"_\" not in col]]\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
364 |
"\n",
|
365 |
"combined_df"
|
366 |
]
|
367 |
},
|
368 |
{
|
369 |
"cell_type": "code",
|
370 |
+
"execution_count": 39,
|
371 |
"metadata": {},
|
372 |
"outputs": [
|
373 |
{
|
|
|
398 |
" <th>State</th>\n",
|
399 |
" <th>Home Type</th>\n",
|
400 |
" <th>Date</th>\n",
|
401 |
+
" <th>Sales Count</th>\n",
|
402 |
" <th>Median Sale Price per Sqft</th>\n",
|
403 |
" <th>Median Sale Price</th>\n",
|
|
|
404 |
" </tr>\n",
|
405 |
" </thead>\n",
|
406 |
" <tbody>\n",
|
|
|
413 |
" <td>NaN</td>\n",
|
414 |
" <td>SFR</td>\n",
|
415 |
" <td>2018-01-31</td>\n",
|
416 |
+
" <td>33940.0</td>\n",
|
417 |
" <td>137.412316</td>\n",
|
418 |
" <td>309000.0</td>\n",
|
|
|
419 |
" </tr>\n",
|
420 |
" <tr>\n",
|
421 |
" <th>1</th>\n",
|
|
|
424 |
" <td>United States</td>\n",
|
425 |
" <td>country</td>\n",
|
426 |
" <td>NaN</td>\n",
|
427 |
+
" <td>SFR</td>\n",
|
428 |
+
" <td>2018-02-28</td>\n",
|
429 |
+
" <td>33304.0</td>\n",
|
430 |
+
" <td>137.199170</td>\n",
|
431 |
+
" <td>309072.5</td>\n",
|
432 |
" </tr>\n",
|
433 |
" <tr>\n",
|
434 |
" <th>2</th>\n",
|
|
|
437 |
" <td>United States</td>\n",
|
438 |
" <td>country</td>\n",
|
439 |
" <td>NaN</td>\n",
|
440 |
+
" <td>SFR</td>\n",
|
441 |
+
" <td>2018-03-31</td>\n",
|
442 |
+
" <td>42641.0</td>\n",
|
443 |
+
" <td>139.520863</td>\n",
|
444 |
+
" <td>315488.0</td>\n",
|
445 |
" </tr>\n",
|
446 |
" <tr>\n",
|
447 |
" <th>3</th>\n",
|
|
|
451 |
" <td>country</td>\n",
|
452 |
" <td>NaN</td>\n",
|
453 |
" <td>SFR</td>\n",
|
454 |
+
" <td>2018-04-30</td>\n",
|
455 |
+
" <td>37588.0</td>\n",
|
456 |
+
" <td>139.778110</td>\n",
|
457 |
+
" <td>314990.0</td>\n",
|
458 |
" </tr>\n",
|
459 |
" <tr>\n",
|
460 |
" <th>4</th>\n",
|
|
|
463 |
" <td>United States</td>\n",
|
464 |
" <td>country</td>\n",
|
465 |
" <td>NaN</td>\n",
|
466 |
+
" <td>SFR</td>\n",
|
467 |
+
" <td>2018-05-31</td>\n",
|
468 |
+
" <td>39933.0</td>\n",
|
469 |
+
" <td>143.317968</td>\n",
|
470 |
+
" <td>324500.0</td>\n",
|
471 |
" </tr>\n",
|
472 |
" <tr>\n",
|
473 |
" <th>...</th>\n",
|
|
|
490 |
" <td>msa</td>\n",
|
491 |
" <td>TX</td>\n",
|
492 |
" <td>all homes</td>\n",
|
493 |
+
" <td>2023-07-31</td>\n",
|
494 |
+
" <td>31.0</td>\n",
|
495 |
" <td>NaN</td>\n",
|
496 |
" <td>NaN</td>\n",
|
|
|
497 |
" </tr>\n",
|
498 |
" <tr>\n",
|
499 |
" <th>49483</th>\n",
|
|
|
502 |
" <td>Granbury, TX</td>\n",
|
503 |
" <td>msa</td>\n",
|
504 |
" <td>TX</td>\n",
|
505 |
+
" <td>all homes</td>\n",
|
506 |
+
" <td>2023-08-31</td>\n",
|
507 |
+
" <td>33.0</td>\n",
|
508 |
" <td>NaN</td>\n",
|
509 |
" <td>NaN</td>\n",
|
|
|
510 |
" </tr>\n",
|
511 |
" <tr>\n",
|
512 |
" <th>49484</th>\n",
|
|
|
516 |
" <td>msa</td>\n",
|
517 |
" <td>TX</td>\n",
|
518 |
" <td>all homes</td>\n",
|
519 |
+
" <td>2023-09-30</td>\n",
|
520 |
+
" <td>26.0</td>\n",
|
521 |
" <td>NaN</td>\n",
|
522 |
" <td>NaN</td>\n",
|
|
|
523 |
" </tr>\n",
|
524 |
" <tr>\n",
|
525 |
" <th>49485</th>\n",
|
|
|
528 |
" <td>Granbury, TX</td>\n",
|
529 |
" <td>msa</td>\n",
|
530 |
" <td>TX</td>\n",
|
531 |
+
" <td>all homes</td>\n",
|
532 |
+
" <td>2023-10-31</td>\n",
|
533 |
+
" <td>24.0</td>\n",
|
534 |
" <td>NaN</td>\n",
|
535 |
" <td>NaN</td>\n",
|
|
|
536 |
" </tr>\n",
|
537 |
" <tr>\n",
|
538 |
" <th>49486</th>\n",
|
|
|
543 |
" <td>TX</td>\n",
|
544 |
" <td>all homes</td>\n",
|
545 |
" <td>2023-11-30</td>\n",
|
546 |
+
" <td>16.0</td>\n",
|
547 |
" <td>NaN</td>\n",
|
548 |
" <td>NaN</td>\n",
|
|
|
549 |
" </tr>\n",
|
550 |
" </tbody>\n",
|
551 |
"</table>\n",
|
|
|
553 |
"</div>"
|
554 |
],
|
555 |
"text/plain": [
|
556 |
+
" Region ID Size Rank Region Region Type State Home Type \\\n",
|
557 |
+
"0 102001 0 United States country NaN SFR \n",
|
558 |
+
"1 102001 0 United States country NaN SFR \n",
|
559 |
+
"2 102001 0 United States country NaN SFR \n",
|
560 |
+
"3 102001 0 United States country NaN SFR \n",
|
561 |
+
"4 102001 0 United States country NaN SFR \n",
|
562 |
+
"... ... ... ... ... ... ... \n",
|
563 |
+
"49482 845162 535 Granbury, TX msa TX all homes \n",
|
564 |
+
"49483 845162 535 Granbury, TX msa TX all homes \n",
|
565 |
+
"49484 845162 535 Granbury, TX msa TX all homes \n",
|
566 |
+
"49485 845162 535 Granbury, TX msa TX all homes \n",
|
567 |
+
"49486 845162 535 Granbury, TX msa TX all homes \n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
568 |
"\n",
|
569 |
+
" Date Sales Count Median Sale Price per Sqft Median Sale Price \n",
|
570 |
+
"0 2018-01-31 33940.0 137.412316 309000.0 \n",
|
571 |
+
"1 2018-02-28 33304.0 137.199170 309072.5 \n",
|
572 |
+
"2 2018-03-31 42641.0 139.520863 315488.0 \n",
|
573 |
+
"3 2018-04-30 37588.0 139.778110 314990.0 \n",
|
574 |
+
"4 2018-05-31 39933.0 143.317968 324500.0 \n",
|
575 |
+
"... ... ... ... ... \n",
|
576 |
+
"49482 2023-07-31 31.0 NaN NaN \n",
|
577 |
+
"49483 2023-08-31 33.0 NaN NaN \n",
|
578 |
+
"49484 2023-09-30 26.0 NaN NaN \n",
|
579 |
+
"49485 2023-10-31 24.0 NaN NaN \n",
|
580 |
+
"49486 2023-11-30 16.0 NaN NaN \n",
|
581 |
"\n",
|
582 |
"[49487 rows x 10 columns]"
|
583 |
]
|
584 |
},
|
585 |
+
"execution_count": 39,
|
586 |
"metadata": {},
|
587 |
"output_type": "execute_result"
|
588 |
}
|
|
|
599 |
" }\n",
|
600 |
")\n",
|
601 |
"\n",
|
602 |
+
"final_df.sort_values(by=[\"Region ID\", \"Home Type\", \"Date\"])"
|
603 |
]
|
604 |
},
|
605 |
{
|
606 |
"cell_type": "code",
|
607 |
+
"execution_count": 40,
|
608 |
"metadata": {},
|
609 |
"outputs": [],
|
610 |
"source": [
|
processors/rentals.ipynb
CHANGED
@@ -25,28 +25,9 @@
|
|
25 |
},
|
26 |
{
|
27 |
"cell_type": "code",
|
28 |
-
"execution_count":
|
29 |
"metadata": {},
|
30 |
"outputs": [
|
31 |
-
{
|
32 |
-
"name": "stdout",
|
33 |
-
"output_type": "stream",
|
34 |
-
"text": [
|
35 |
-
"Index(['RegionID', 'SizeRank', 'RegionName', 'RegionType', 'StateName',\n",
|
36 |
-
" 'Home Type', 'Date', 'Rent (Smoothed)'],\n",
|
37 |
-
" dtype='object')\n",
|
38 |
-
"['Rent (Smoothed) (Seasonally Adjusted)', 'RegionID', 'Home Type', 'Date']\n",
|
39 |
-
"Index(['RegionID', 'SizeRank', 'RegionName', 'RegionType', 'StateName',\n",
|
40 |
-
" 'Home Type', 'Date', 'Rent (Smoothed)',\n",
|
41 |
-
" 'Rent (Smoothed) (Seasonally Adjusted)'],\n",
|
42 |
-
" dtype='object')\n",
|
43 |
-
"['RegionID', 'Home Type', 'Date']\n",
|
44 |
-
"Index(['RegionID', 'SizeRank', 'RegionName', 'RegionType', 'StateName',\n",
|
45 |
-
" 'Home Type', 'Date', 'Rent (Smoothed)',\n",
|
46 |
-
" 'Rent (Smoothed) (Seasonally Adjusted)'],\n",
|
47 |
-
" dtype='object')\n"
|
48 |
-
]
|
49 |
-
},
|
50 |
{
|
51 |
"data": {
|
52 |
"text/html": [
|
@@ -197,8 +178,8 @@
|
|
197 |
" <td>IL</td>\n",
|
198 |
" <td>multifamily</td>\n",
|
199 |
" <td>2023-11-30</td>\n",
|
200 |
-
" <td>
|
201 |
-
" <td>
|
202 |
" </tr>\n",
|
203 |
" <tr>\n",
|
204 |
" <th>96011</th>\n",
|
@@ -210,7 +191,7 @@
|
|
210 |
" <td>multifamily</td>\n",
|
211 |
" <td>2023-12-31</td>\n",
|
212 |
" <td>800.000000</td>\n",
|
213 |
-
" <td>
|
214 |
" </tr>\n",
|
215 |
" </tbody>\n",
|
216 |
"</table>\n",
|
@@ -241,13 +222,13 @@
|
|
241 |
"96007 2023-08-31 NaN NaN \n",
|
242 |
"96008 2023-09-30 NaN NaN \n",
|
243 |
"96009 2023-10-31 NaN NaN \n",
|
244 |
-
"96010 2023-11-30
|
245 |
-
"96011 2023-12-31 800.000000
|
246 |
"\n",
|
247 |
"[96012 rows x 9 columns]"
|
248 |
]
|
249 |
},
|
250 |
-
"execution_count":
|
251 |
"metadata": {},
|
252 |
"output_type": "execute_result"
|
253 |
}
|
@@ -264,7 +245,7 @@
|
|
264 |
" \"Home Type\",\n",
|
265 |
"]\n",
|
266 |
"\n",
|
267 |
-
"
|
268 |
"\n",
|
269 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
270 |
" if filename.endswith(\".csv\"):\n",
|
@@ -299,7 +280,7 @@
|
|
299 |
" var_name=\"Date\",\n",
|
300 |
" value_name=col_name,\n",
|
301 |
" )\n",
|
302 |
-
"
|
303 |
" # print(filename)\n",
|
304 |
"\n",
|
305 |
"\n",
|
@@ -310,39 +291,257 @@
|
|
310 |
" combined_df = data_frames[0]\n",
|
311 |
" for i in range(1, len(data_frames)):\n",
|
312 |
" cur_df = data_frames[i]\n",
|
313 |
-
"
|
314 |
-
" combined_df
|
315 |
-
"
|
316 |
-
"
|
317 |
-
"
|
318 |
-
"
|
319 |
-
"
|
320 |
-
"
|
321 |
-
"
|
322 |
-
"\n",
|
323 |
-
"
|
324 |
-
"
|
325 |
-
"
|
326 |
-
"
|
327 |
-
"
|
328 |
-
" )\n",
|
329 |
-
"\n",
|
330 |
-
" print(combined_df.columns)\n",
|
331 |
" elif len(data_frames) == 1:\n",
|
332 |
" combined_df = data_frames[0]\n",
|
333 |
"\n",
|
334 |
" return combined_df\n",
|
335 |
"\n",
|
336 |
"\n",
|
337 |
-
"combined_df = get_combined_df(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
"combined_df"
|
339 |
]
|
340 |
},
|
341 |
{
|
342 |
"cell_type": "code",
|
343 |
-
"execution_count":
|
344 |
"metadata": {},
|
345 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
"source": [
|
347 |
"final_df = combined_df\n",
|
348 |
"final_df = final_df.rename(\n",
|
@@ -356,12 +555,12 @@
|
|
356 |
")\n",
|
357 |
"\n",
|
358 |
"# sort by region id and date\n",
|
359 |
-
"
|
360 |
]
|
361 |
},
|
362 |
{
|
363 |
"cell_type": "code",
|
364 |
-
"execution_count":
|
365 |
"metadata": {},
|
366 |
"outputs": [],
|
367 |
"source": [
|
|
|
25 |
},
|
26 |
{
|
27 |
"cell_type": "code",
|
28 |
+
"execution_count": 79,
|
29 |
"metadata": {},
|
30 |
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
{
|
32 |
"data": {
|
33 |
"text/html": [
|
|
|
178 |
" <td>IL</td>\n",
|
179 |
" <td>multifamily</td>\n",
|
180 |
" <td>2023-11-30</td>\n",
|
181 |
+
" <td>802.086919</td>\n",
|
182 |
+
" <td>802.086919</td>\n",
|
183 |
" </tr>\n",
|
184 |
" <tr>\n",
|
185 |
" <th>96011</th>\n",
|
|
|
191 |
" <td>multifamily</td>\n",
|
192 |
" <td>2023-12-31</td>\n",
|
193 |
" <td>800.000000</td>\n",
|
194 |
+
" <td>800.000000</td>\n",
|
195 |
" </tr>\n",
|
196 |
" </tbody>\n",
|
197 |
"</table>\n",
|
|
|
222 |
"96007 2023-08-31 NaN NaN \n",
|
223 |
"96008 2023-09-30 NaN NaN \n",
|
224 |
"96009 2023-10-31 NaN NaN \n",
|
225 |
+
"96010 2023-11-30 802.086919 802.086919 \n",
|
226 |
+
"96011 2023-12-31 800.000000 800.000000 \n",
|
227 |
"\n",
|
228 |
"[96012 rows x 9 columns]"
|
229 |
]
|
230 |
},
|
231 |
+
"execution_count": 79,
|
232 |
"metadata": {},
|
233 |
"output_type": "execute_result"
|
234 |
}
|
|
|
245 |
" \"Home Type\",\n",
|
246 |
"]\n",
|
247 |
"\n",
|
248 |
+
"data_frames = []\n",
|
249 |
"\n",
|
250 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
251 |
" if filename.endswith(\".csv\"):\n",
|
|
|
280 |
" var_name=\"Date\",\n",
|
281 |
" value_name=col_name,\n",
|
282 |
" )\n",
|
283 |
+
" data_frames.append(cur_df)\n",
|
284 |
" # print(filename)\n",
|
285 |
"\n",
|
286 |
"\n",
|
|
|
291 |
" combined_df = data_frames[0]\n",
|
292 |
" for i in range(1, len(data_frames)):\n",
|
293 |
" cur_df = data_frames[i]\n",
|
294 |
+
" combined_df = pd.merge(\n",
|
295 |
+
" combined_df,\n",
|
296 |
+
" cur_df,\n",
|
297 |
+
" on=[\n",
|
298 |
+
" \"RegionID\",\n",
|
299 |
+
" \"SizeRank\",\n",
|
300 |
+
" \"RegionName\",\n",
|
301 |
+
" \"RegionType\",\n",
|
302 |
+
" \"StateName\",\n",
|
303 |
+
" \"Home Type\",\n",
|
304 |
+
" \"Date\",\n",
|
305 |
+
" ],\n",
|
306 |
+
" how=\"outer\",\n",
|
307 |
+
" suffixes=(\"\", \"_\" + str(i)),\n",
|
308 |
+
" )\n",
|
|
|
|
|
|
|
309 |
" elif len(data_frames) == 1:\n",
|
310 |
" combined_df = data_frames[0]\n",
|
311 |
"\n",
|
312 |
" return combined_df\n",
|
313 |
"\n",
|
314 |
"\n",
|
315 |
+
"combined_df = get_combined_df(data_frames)\n",
|
316 |
+
"\n",
|
317 |
+
"\n",
|
318 |
+
"# iterate over rows of combined df and coalesce column values across columns that start with \"Median Sale Price\"\n",
|
319 |
+
"columns_to_coalesce = [\"Rent (Smoothed)\", \"Rent (Smoothed) (Seasonally Adjusted)\"]\n",
|
320 |
+
"\n",
|
321 |
+
"for index, row in combined_df.iterrows():\n",
|
322 |
+
" for col in combined_df.columns:\n",
|
323 |
+
" for column_to_coalesce in columns_to_coalesce:\n",
|
324 |
+
" if column_to_coalesce in col and \"_\" in col:\n",
|
325 |
+
" if not pd.isna(row[col]):\n",
|
326 |
+
" combined_df.at[index, column_to_coalesce] = row[col]\n",
|
327 |
+
"\n",
|
328 |
+
"# remove columns with underscores\n",
|
329 |
+
"combined_df = combined_df[[col for col in combined_df.columns if \"_\" not in col]]\n",
|
330 |
+
"\n",
|
331 |
+
"\n",
|
332 |
"combined_df"
|
333 |
]
|
334 |
},
|
335 |
{
|
336 |
"cell_type": "code",
|
337 |
+
"execution_count": 80,
|
338 |
"metadata": {},
|
339 |
+
"outputs": [
|
340 |
+
{
|
341 |
+
"data": {
|
342 |
+
"text/html": [
|
343 |
+
"<div>\n",
|
344 |
+
"<style scoped>\n",
|
345 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
346 |
+
" vertical-align: middle;\n",
|
347 |
+
" }\n",
|
348 |
+
"\n",
|
349 |
+
" .dataframe tbody tr th {\n",
|
350 |
+
" vertical-align: top;\n",
|
351 |
+
" }\n",
|
352 |
+
"\n",
|
353 |
+
" .dataframe thead th {\n",
|
354 |
+
" text-align: right;\n",
|
355 |
+
" }\n",
|
356 |
+
"</style>\n",
|
357 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
358 |
+
" <thead>\n",
|
359 |
+
" <tr style=\"text-align: right;\">\n",
|
360 |
+
" <th></th>\n",
|
361 |
+
" <th>Region ID</th>\n",
|
362 |
+
" <th>Size Rank</th>\n",
|
363 |
+
" <th>Region</th>\n",
|
364 |
+
" <th>Region Type</th>\n",
|
365 |
+
" <th>State</th>\n",
|
366 |
+
" <th>Home Type</th>\n",
|
367 |
+
" <th>Date</th>\n",
|
368 |
+
" <th>Rent (Smoothed)</th>\n",
|
369 |
+
" <th>Rent (Smoothed) (Seasonally Adjusted)</th>\n",
|
370 |
+
" </tr>\n",
|
371 |
+
" </thead>\n",
|
372 |
+
" <tbody>\n",
|
373 |
+
" <tr>\n",
|
374 |
+
" <th>0</th>\n",
|
375 |
+
" <td>102001</td>\n",
|
376 |
+
" <td>0</td>\n",
|
377 |
+
" <td>United States</td>\n",
|
378 |
+
" <td>country</td>\n",
|
379 |
+
" <td>NaN</td>\n",
|
380 |
+
" <td>SFR</td>\n",
|
381 |
+
" <td>2015-01-31</td>\n",
|
382 |
+
" <td>1251.119548</td>\n",
|
383 |
+
" <td>1253.380721</td>\n",
|
384 |
+
" </tr>\n",
|
385 |
+
" <tr>\n",
|
386 |
+
" <th>108</th>\n",
|
387 |
+
" <td>102001</td>\n",
|
388 |
+
" <td>0</td>\n",
|
389 |
+
" <td>United States</td>\n",
|
390 |
+
" <td>country</td>\n",
|
391 |
+
" <td>NaN</td>\n",
|
392 |
+
" <td>multifamily</td>\n",
|
393 |
+
" <td>2015-01-31</td>\n",
|
394 |
+
" <td>1230.637976</td>\n",
|
395 |
+
" <td>1230.637976</td>\n",
|
396 |
+
" </tr>\n",
|
397 |
+
" <tr>\n",
|
398 |
+
" <th>1</th>\n",
|
399 |
+
" <td>102001</td>\n",
|
400 |
+
" <td>0</td>\n",
|
401 |
+
" <td>United States</td>\n",
|
402 |
+
" <td>country</td>\n",
|
403 |
+
" <td>NaN</td>\n",
|
404 |
+
" <td>SFR</td>\n",
|
405 |
+
" <td>2015-02-28</td>\n",
|
406 |
+
" <td>1257.678915</td>\n",
|
407 |
+
" <td>1258.745304</td>\n",
|
408 |
+
" </tr>\n",
|
409 |
+
" <tr>\n",
|
410 |
+
" <th>109</th>\n",
|
411 |
+
" <td>102001</td>\n",
|
412 |
+
" <td>0</td>\n",
|
413 |
+
" <td>United States</td>\n",
|
414 |
+
" <td>country</td>\n",
|
415 |
+
" <td>NaN</td>\n",
|
416 |
+
" <td>multifamily</td>\n",
|
417 |
+
" <td>2015-02-28</td>\n",
|
418 |
+
" <td>1236.170604</td>\n",
|
419 |
+
" <td>1236.170604</td>\n",
|
420 |
+
" </tr>\n",
|
421 |
+
" <tr>\n",
|
422 |
+
" <th>2</th>\n",
|
423 |
+
" <td>102001</td>\n",
|
424 |
+
" <td>0</td>\n",
|
425 |
+
" <td>United States</td>\n",
|
426 |
+
" <td>country</td>\n",
|
427 |
+
" <td>NaN</td>\n",
|
428 |
+
" <td>SFR</td>\n",
|
429 |
+
" <td>2015-03-31</td>\n",
|
430 |
+
" <td>1266.242657</td>\n",
|
431 |
+
" <td>1263.914519</td>\n",
|
432 |
+
" </tr>\n",
|
433 |
+
" <tr>\n",
|
434 |
+
" <th>...</th>\n",
|
435 |
+
" <td>...</td>\n",
|
436 |
+
" <td>...</td>\n",
|
437 |
+
" <td>...</td>\n",
|
438 |
+
" <td>...</td>\n",
|
439 |
+
" <td>...</td>\n",
|
440 |
+
" <td>...</td>\n",
|
441 |
+
" <td>...</td>\n",
|
442 |
+
" <td>...</td>\n",
|
443 |
+
" <td>...</td>\n",
|
444 |
+
" </tr>\n",
|
445 |
+
" <tr>\n",
|
446 |
+
" <th>96007</th>\n",
|
447 |
+
" <td>845167</td>\n",
|
448 |
+
" <td>296</td>\n",
|
449 |
+
" <td>Ottawa, IL</td>\n",
|
450 |
+
" <td>msa</td>\n",
|
451 |
+
" <td>IL</td>\n",
|
452 |
+
" <td>multifamily</td>\n",
|
453 |
+
" <td>2023-08-31</td>\n",
|
454 |
+
" <td>NaN</td>\n",
|
455 |
+
" <td>NaN</td>\n",
|
456 |
+
" </tr>\n",
|
457 |
+
" <tr>\n",
|
458 |
+
" <th>96008</th>\n",
|
459 |
+
" <td>845167</td>\n",
|
460 |
+
" <td>296</td>\n",
|
461 |
+
" <td>Ottawa, IL</td>\n",
|
462 |
+
" <td>msa</td>\n",
|
463 |
+
" <td>IL</td>\n",
|
464 |
+
" <td>multifamily</td>\n",
|
465 |
+
" <td>2023-09-30</td>\n",
|
466 |
+
" <td>NaN</td>\n",
|
467 |
+
" <td>NaN</td>\n",
|
468 |
+
" </tr>\n",
|
469 |
+
" <tr>\n",
|
470 |
+
" <th>96009</th>\n",
|
471 |
+
" <td>845167</td>\n",
|
472 |
+
" <td>296</td>\n",
|
473 |
+
" <td>Ottawa, IL</td>\n",
|
474 |
+
" <td>msa</td>\n",
|
475 |
+
" <td>IL</td>\n",
|
476 |
+
" <td>multifamily</td>\n",
|
477 |
+
" <td>2023-10-31</td>\n",
|
478 |
+
" <td>NaN</td>\n",
|
479 |
+
" <td>NaN</td>\n",
|
480 |
+
" </tr>\n",
|
481 |
+
" <tr>\n",
|
482 |
+
" <th>96010</th>\n",
|
483 |
+
" <td>845167</td>\n",
|
484 |
+
" <td>296</td>\n",
|
485 |
+
" <td>Ottawa, IL</td>\n",
|
486 |
+
" <td>msa</td>\n",
|
487 |
+
" <td>IL</td>\n",
|
488 |
+
" <td>multifamily</td>\n",
|
489 |
+
" <td>2023-11-30</td>\n",
|
490 |
+
" <td>802.086919</td>\n",
|
491 |
+
" <td>802.086919</td>\n",
|
492 |
+
" </tr>\n",
|
493 |
+
" <tr>\n",
|
494 |
+
" <th>96011</th>\n",
|
495 |
+
" <td>845167</td>\n",
|
496 |
+
" <td>296</td>\n",
|
497 |
+
" <td>Ottawa, IL</td>\n",
|
498 |
+
" <td>msa</td>\n",
|
499 |
+
" <td>IL</td>\n",
|
500 |
+
" <td>multifamily</td>\n",
|
501 |
+
" <td>2023-12-31</td>\n",
|
502 |
+
" <td>800.000000</td>\n",
|
503 |
+
" <td>800.000000</td>\n",
|
504 |
+
" </tr>\n",
|
505 |
+
" </tbody>\n",
|
506 |
+
"</table>\n",
|
507 |
+
"<p>96012 rows Γ 9 columns</p>\n",
|
508 |
+
"</div>"
|
509 |
+
],
|
510 |
+
"text/plain": [
|
511 |
+
" Region ID Size Rank Region Region Type State Home Type \\\n",
|
512 |
+
"0 102001 0 United States country NaN SFR \n",
|
513 |
+
"108 102001 0 United States country NaN multifamily \n",
|
514 |
+
"1 102001 0 United States country NaN SFR \n",
|
515 |
+
"109 102001 0 United States country NaN multifamily \n",
|
516 |
+
"2 102001 0 United States country NaN SFR \n",
|
517 |
+
"... ... ... ... ... ... ... \n",
|
518 |
+
"96007 845167 296 Ottawa, IL msa IL multifamily \n",
|
519 |
+
"96008 845167 296 Ottawa, IL msa IL multifamily \n",
|
520 |
+
"96009 845167 296 Ottawa, IL msa IL multifamily \n",
|
521 |
+
"96010 845167 296 Ottawa, IL msa IL multifamily \n",
|
522 |
+
"96011 845167 296 Ottawa, IL msa IL multifamily \n",
|
523 |
+
"\n",
|
524 |
+
" Date Rent (Smoothed) Rent (Smoothed) (Seasonally Adjusted) \n",
|
525 |
+
"0 2015-01-31 1251.119548 1253.380721 \n",
|
526 |
+
"108 2015-01-31 1230.637976 1230.637976 \n",
|
527 |
+
"1 2015-02-28 1257.678915 1258.745304 \n",
|
528 |
+
"109 2015-02-28 1236.170604 1236.170604 \n",
|
529 |
+
"2 2015-03-31 1266.242657 1263.914519 \n",
|
530 |
+
"... ... ... ... \n",
|
531 |
+
"96007 2023-08-31 NaN NaN \n",
|
532 |
+
"96008 2023-09-30 NaN NaN \n",
|
533 |
+
"96009 2023-10-31 NaN NaN \n",
|
534 |
+
"96010 2023-11-30 802.086919 802.086919 \n",
|
535 |
+
"96011 2023-12-31 800.000000 800.000000 \n",
|
536 |
+
"\n",
|
537 |
+
"[96012 rows x 9 columns]"
|
538 |
+
]
|
539 |
+
},
|
540 |
+
"execution_count": 80,
|
541 |
+
"metadata": {},
|
542 |
+
"output_type": "execute_result"
|
543 |
+
}
|
544 |
+
],
|
545 |
"source": [
|
546 |
"final_df = combined_df\n",
|
547 |
"final_df = final_df.rename(\n",
|
|
|
555 |
")\n",
|
556 |
"\n",
|
557 |
"# sort by region id and date\n",
|
558 |
+
"final_df.sort_values(by=[\"Region ID\", \"Date\", \"Home Type\"])"
|
559 |
]
|
560 |
},
|
561 |
{
|
562 |
"cell_type": "code",
|
563 |
+
"execution_count": 81,
|
564 |
"metadata": {},
|
565 |
"outputs": [],
|
566 |
"source": [
|
tester.ipynb
CHANGED
@@ -22,18 +22,18 @@
|
|
22 |
},
|
23 |
{
|
24 |
"cell_type": "code",
|
25 |
-
"execution_count":
|
26 |
"metadata": {},
|
27 |
"outputs": [
|
28 |
{
|
29 |
"name": "stderr",
|
30 |
"output_type": "stream",
|
31 |
"text": [
|
32 |
-
"Downloading builder script: 100%|ββββββββββ|
|
33 |
-
"Downloading data: 100%|ββββββββββ|
|
34 |
-
"Generating train split:
|
35 |
-
"Generating validation split:
|
36 |
-
"Generating test split:
|
37 |
]
|
38 |
}
|
39 |
],
|
|
|
22 |
},
|
23 |
{
|
24 |
"cell_type": "code",
|
25 |
+
"execution_count": 4,
|
26 |
"metadata": {},
|
27 |
"outputs": [
|
28 |
{
|
29 |
"name": "stderr",
|
30 |
"output_type": "stream",
|
31 |
"text": [
|
32 |
+
"Downloading builder script: 100%|ββββββββββ| 18.5k/18.5k [00:00<00:00, 11.3MB/s]\n",
|
33 |
+
"Downloading data: 100%|ββββββββββ| 20.4M/20.4M [00:00<00:00, 33.6MB/s]\n",
|
34 |
+
"Generating train split: 96012 examples [00:02, 46188.04 examples/s]\n",
|
35 |
+
"Generating validation split: 96012 examples [00:02, 47013.79 examples/s]\n",
|
36 |
+
"Generating test split: 96012 examples [00:02, 46947.45 examples/s]\n"
|
37 |
]
|
38 |
}
|
39 |
],
|