fix: widen df a little
Browse files- processed/new_constructions/final.jsonl +2 -2
- processors/process_new_constructions.ipynb +320 -240
- zillow.py +8 -2
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:4cbd1713a383959a9c43afb152cf8dd169b584b809b1c940c9b48ae8b8d8a8e6
|
3 |
+
size 9865188
|
processors/process_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 |
{
|
@@ -69,10 +69,11 @@
|
|
69 |
" <th>RegionName</th>\n",
|
70 |
" <th>RegionType</th>\n",
|
71 |
" <th>StateName</th>\n",
|
72 |
-
" <th>Value Type</th>\n",
|
73 |
" <th>Home Type</th>\n",
|
74 |
" <th>Date</th>\n",
|
75 |
-
" <th>
|
|
|
|
|
76 |
" </tr>\n",
|
77 |
" </thead>\n",
|
78 |
" <tbody>\n",
|
@@ -83,58 +84,63 @@
|
|
83 |
" <td>United States</td>\n",
|
84 |
" <td>country</td>\n",
|
85 |
" <td>NaN</td>\n",
|
86 |
-
" <td>
|
87 |
-
" <td>Condo</td>\n",
|
88 |
" <td>2018-01-31</td>\n",
|
89 |
-
" <td>
|
|
|
|
|
90 |
" </tr>\n",
|
91 |
" <tr>\n",
|
92 |
" <th>1</th>\n",
|
93 |
-
" <td>
|
94 |
-
" <td>
|
95 |
-
" <td>
|
96 |
-
" <td>
|
97 |
-
" <td>
|
98 |
-
" <td>
|
99 |
-
" <td>Condo</td>\n",
|
100 |
" <td>2018-01-31</td>\n",
|
101 |
-
" <td>
|
|
|
|
|
102 |
" </tr>\n",
|
103 |
" <tr>\n",
|
104 |
" <th>2</th>\n",
|
105 |
-
" <td>
|
106 |
-
" <td>
|
107 |
-
" <td>
|
108 |
-
" <td>
|
109 |
-
" <td>
|
110 |
-
" <td>
|
111 |
-
" <td>Condo</td>\n",
|
112 |
" <td>2018-01-31</td>\n",
|
113 |
-
" <td>
|
|
|
|
|
114 |
" </tr>\n",
|
115 |
" <tr>\n",
|
116 |
" <th>3</th>\n",
|
117 |
-
" <td>
|
118 |
-
" <td>
|
119 |
-
" <td>
|
120 |
-
" <td>
|
121 |
-
" <td>VA</td>\n",
|
122 |
-
" <td>Count</td>\n",
|
123 |
-
" <td>Condo</td>\n",
|
124 |
-
" <td>2018-01-31</td>\n",
|
125 |
" <td>NaN</td>\n",
|
|
|
|
|
|
|
|
|
|
|
126 |
" </tr>\n",
|
127 |
" <tr>\n",
|
128 |
" <th>4</th>\n",
|
129 |
-
" <td>
|
130 |
-
" <td>
|
131 |
-
" <td>
|
132 |
-
" <td>
|
133 |
-
" <td>
|
134 |
-
" <td>
|
135 |
-
" <td>
|
136 |
-
" <td>
|
137 |
-
" <td>
|
|
|
138 |
" </tr>\n",
|
139 |
" <tr>\n",
|
140 |
" <th>...</th>\n",
|
@@ -147,103 +153,109 @@
|
|
147 |
" <td>...</td>\n",
|
148 |
" <td>...</td>\n",
|
149 |
" <td>...</td>\n",
|
|
|
150 |
" </tr>\n",
|
151 |
" <tr>\n",
|
152 |
-
" <th>
|
153 |
-
" <td>
|
154 |
-
" <td>
|
155 |
-
" <td>
|
156 |
" <td>msa</td>\n",
|
157 |
-
" <td>
|
158 |
-
" <td>
|
159 |
-
" <td>
|
160 |
-
" <td>
|
161 |
-
" <td>
|
|
|
162 |
" </tr>\n",
|
163 |
" <tr>\n",
|
164 |
-
" <th>
|
165 |
-
" <td>
|
166 |
-
" <td>
|
167 |
-
" <td>
|
168 |
" <td>msa</td>\n",
|
169 |
-
" <td>
|
170 |
-
" <td>
|
171 |
-
" <td>
|
172 |
-
" <td>
|
173 |
-
" <td>
|
|
|
174 |
" </tr>\n",
|
175 |
" <tr>\n",
|
176 |
-
" <th>
|
177 |
-
" <td>
|
178 |
-
" <td>
|
179 |
-
" <td>
|
180 |
" <td>msa</td>\n",
|
181 |
-
" <td>
|
182 |
-
" <td>
|
183 |
-
" <td>
|
184 |
-
" <td>
|
185 |
-
" <td>
|
|
|
186 |
" </tr>\n",
|
187 |
" <tr>\n",
|
188 |
-
" <th>
|
189 |
-
" <td>
|
190 |
-
" <td>
|
191 |
-
" <td>
|
192 |
" <td>msa</td>\n",
|
193 |
-
" <td>
|
194 |
-
" <td>
|
195 |
-
" <td>SFR/Condo</td>\n",
|
196 |
" <td>2023-11-30</td>\n",
|
197 |
-
" <td>
|
|
|
|
|
198 |
" </tr>\n",
|
199 |
" <tr>\n",
|
200 |
-
" <th>
|
201 |
-
" <td>
|
202 |
-
" <td>
|
203 |
-
" <td>
|
204 |
" <td>msa</td>\n",
|
205 |
-
" <td>
|
206 |
-
" <td>
|
207 |
-
" <td>SFR/Condo</td>\n",
|
208 |
" <td>2023-11-30</td>\n",
|
209 |
-
" <td>
|
|
|
|
|
210 |
" </tr>\n",
|
211 |
" </tbody>\n",
|
212 |
"</table>\n",
|
213 |
-
"<p>
|
214 |
"</div>"
|
215 |
],
|
216 |
"text/plain": [
|
217 |
-
" RegionID SizeRank
|
218 |
-
"0 102001 0
|
219 |
-
"1
|
220 |
-
"2
|
221 |
-
"3
|
222 |
-
"4
|
223 |
-
"... ... ...
|
224 |
-
"
|
225 |
-
"
|
226 |
-
"
|
227 |
-
"
|
228 |
-
"
|
229 |
"\n",
|
230 |
-
"
|
231 |
-
"0
|
232 |
-
"1
|
233 |
-
"2
|
234 |
-
"3
|
235 |
-
"4
|
236 |
-
"...
|
237 |
-
"
|
238 |
-
"
|
239 |
-
"
|
240 |
-
"
|
241 |
-
"
|
242 |
"\n",
|
243 |
-
"[
|
244 |
]
|
245 |
},
|
246 |
-
"execution_count":
|
247 |
"metadata": {},
|
248 |
"output_type": "execute_result"
|
249 |
}
|
@@ -259,49 +271,98 @@
|
|
259 |
" \"RegionName\",\n",
|
260 |
" \"RegionType\",\n",
|
261 |
" \"StateName\",\n",
|
262 |
-
" \"Value Type\",\n",
|
263 |
" \"Home Type\",\n",
|
264 |
"]\n",
|
265 |
"\n",
|
|
|
|
|
|
|
|
|
266 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
267 |
" if filename.endswith(\".csv\"):\n",
|
268 |
" print(\"processing \" + filename)\n",
|
269 |
" cur_df = pd.read_csv(os.path.join(FULL_DATA_DIR_PATH, filename))\n",
|
270 |
-
" if \"sale_price_per_sqft\" in filename:\n",
|
271 |
-
" cur_df[\"Value Type\"] = \"Sale Price Per Sqft\"\n",
|
272 |
-
" elif \"sale_price_uc\" in filename:\n",
|
273 |
-
" cur_df[\"Value Type\"] = \"Sale Price\"\n",
|
274 |
-
" elif \"count\" in filename:\n",
|
275 |
-
" cur_df[\"Value Type\"] = \"Count\"\n",
|
276 |
"\n",
|
277 |
" if \"sfrcondo\" in filename:\n",
|
278 |
-
" cur_df[\"Home Type\"] = \"
|
279 |
" elif \"sfr\" in filename:\n",
|
280 |
" cur_df[\"Home Type\"] = \"SFR\"\n",
|
281 |
" elif \"condo\" in filename:\n",
|
282 |
-
" cur_df[\"Home Type\"] = \"
|
283 |
"\n",
|
284 |
" # Identify columns to pivot\n",
|
285 |
" columns_to_pivot = [col for col in cur_df.columns if col not in exclude_columns]\n",
|
286 |
"\n",
|
287 |
-
"
|
288 |
-
"
|
289 |
-
"
|
290 |
-
"
|
291 |
-
"
|
292 |
-
"
|
293 |
-
"
|
294 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
"\n",
|
296 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
"\n",
|
298 |
-
"combined_df = pd.concat(data_frames)\n",
|
299 |
"combined_df"
|
300 |
]
|
301 |
},
|
302 |
{
|
303 |
"cell_type": "code",
|
304 |
-
"execution_count":
|
305 |
"metadata": {},
|
306 |
"outputs": [
|
307 |
{
|
@@ -330,10 +391,11 @@
|
|
330 |
" <th>Region</th>\n",
|
331 |
" <th>Region Type</th>\n",
|
332 |
" <th>State</th>\n",
|
333 |
-
" <th>Value Type</th>\n",
|
334 |
" <th>Home Type</th>\n",
|
335 |
" <th>Date</th>\n",
|
336 |
-
" <th>
|
|
|
|
|
337 |
" </tr>\n",
|
338 |
" </thead>\n",
|
339 |
" <tbody>\n",
|
@@ -344,58 +406,63 @@
|
|
344 |
" <td>United States</td>\n",
|
345 |
" <td>country</td>\n",
|
346 |
" <td>NaN</td>\n",
|
347 |
-
" <td>
|
348 |
-
" <td>Condo</td>\n",
|
349 |
" <td>2018-01-31</td>\n",
|
350 |
-
" <td>
|
|
|
|
|
351 |
" </tr>\n",
|
352 |
" <tr>\n",
|
353 |
" <th>1</th>\n",
|
354 |
-
" <td>
|
355 |
-
" <td>
|
356 |
-
" <td>
|
357 |
-
" <td>
|
358 |
-
" <td>
|
359 |
-
" <td>
|
360 |
-
" <td>Condo</td>\n",
|
361 |
" <td>2018-01-31</td>\n",
|
362 |
-
" <td>
|
|
|
|
|
363 |
" </tr>\n",
|
364 |
" <tr>\n",
|
365 |
" <th>2</th>\n",
|
366 |
-
" <td>
|
367 |
-
" <td>
|
368 |
-
" <td>
|
369 |
-
" <td>
|
370 |
-
" <td>
|
371 |
-
" <td>
|
372 |
-
" <td>Condo</td>\n",
|
373 |
" <td>2018-01-31</td>\n",
|
374 |
-
" <td>
|
|
|
|
|
375 |
" </tr>\n",
|
376 |
" <tr>\n",
|
377 |
" <th>3</th>\n",
|
378 |
-
" <td>
|
379 |
-
" <td>
|
380 |
-
" <td>
|
381 |
-
" <td>
|
382 |
-
" <td>VA</td>\n",
|
383 |
-
" <td>Count</td>\n",
|
384 |
-
" <td>Condo</td>\n",
|
385 |
-
" <td>2018-01-31</td>\n",
|
386 |
" <td>NaN</td>\n",
|
|
|
|
|
|
|
|
|
|
|
387 |
" </tr>\n",
|
388 |
" <tr>\n",
|
389 |
" <th>4</th>\n",
|
390 |
-
" <td>
|
391 |
-
" <td>
|
392 |
-
" <td>
|
393 |
-
" <td>
|
394 |
-
" <td>
|
395 |
-
" <td>
|
396 |
-
" <td>
|
397 |
-
" <td>
|
398 |
-
" <td>
|
|
|
399 |
" </tr>\n",
|
400 |
" <tr>\n",
|
401 |
" <th>...</th>\n",
|
@@ -408,103 +475,109 @@
|
|
408 |
" <td>...</td>\n",
|
409 |
" <td>...</td>\n",
|
410 |
" <td>...</td>\n",
|
|
|
411 |
" </tr>\n",
|
412 |
" <tr>\n",
|
413 |
-
" <th>
|
414 |
-
" <td>
|
415 |
-
" <td>
|
416 |
-
" <td>
|
417 |
" <td>msa</td>\n",
|
418 |
-
" <td>
|
419 |
-
" <td>
|
420 |
-
" <td>
|
421 |
-
" <td>
|
422 |
-
" <td>
|
|
|
423 |
" </tr>\n",
|
424 |
" <tr>\n",
|
425 |
-
" <th>
|
426 |
-
" <td>
|
427 |
-
" <td>
|
428 |
-
" <td>
|
429 |
" <td>msa</td>\n",
|
430 |
-
" <td>
|
431 |
-
" <td>
|
432 |
-
" <td>
|
433 |
-
" <td>
|
434 |
-
" <td>
|
|
|
435 |
" </tr>\n",
|
436 |
" <tr>\n",
|
437 |
-
" <th>
|
438 |
-
" <td>
|
439 |
-
" <td>
|
440 |
-
" <td>
|
441 |
" <td>msa</td>\n",
|
442 |
-
" <td>
|
443 |
-
" <td>
|
444 |
-
" <td>
|
445 |
-
" <td>
|
446 |
-
" <td>
|
|
|
447 |
" </tr>\n",
|
448 |
" <tr>\n",
|
449 |
-
" <th>
|
450 |
-
" <td>
|
451 |
-
" <td>
|
452 |
-
" <td>
|
453 |
" <td>msa</td>\n",
|
454 |
-
" <td>
|
455 |
-
" <td>
|
456 |
-
" <td>SFR/Condo</td>\n",
|
457 |
" <td>2023-11-30</td>\n",
|
458 |
-
" <td>
|
|
|
|
|
459 |
" </tr>\n",
|
460 |
" <tr>\n",
|
461 |
-
" <th>
|
462 |
-
" <td>
|
463 |
-
" <td>
|
464 |
-
" <td>
|
465 |
" <td>msa</td>\n",
|
466 |
-
" <td>
|
467 |
-
" <td>
|
468 |
-
" <td>SFR/Condo</td>\n",
|
469 |
" <td>2023-11-30</td>\n",
|
470 |
-
" <td>
|
|
|
|
|
471 |
" </tr>\n",
|
472 |
" </tbody>\n",
|
473 |
"</table>\n",
|
474 |
-
"<p>
|
475 |
"</div>"
|
476 |
],
|
477 |
"text/plain": [
|
478 |
-
" Region ID Size Rank
|
479 |
-
"0 102001 0
|
480 |
-
"1
|
481 |
-
"2
|
482 |
-
"3
|
483 |
-
"4
|
484 |
-
"... ... ...
|
485 |
-
"
|
486 |
-
"
|
487 |
-
"
|
488 |
-
"
|
489 |
-
"
|
490 |
"\n",
|
491 |
-
"
|
492 |
-
"0
|
493 |
-
"1
|
494 |
-
"2
|
495 |
-
"3
|
496 |
-
"4
|
497 |
-
"...
|
498 |
-
"
|
499 |
-
"
|
500 |
-
"
|
501 |
-
"
|
502 |
-
"
|
503 |
"\n",
|
504 |
-
"[
|
505 |
]
|
506 |
},
|
507 |
-
"execution_count":
|
508 |
"metadata": {},
|
509 |
"output_type": "execute_result"
|
510 |
}
|
@@ -526,7 +599,7 @@
|
|
526 |
},
|
527 |
{
|
528 |
"cell_type": "code",
|
529 |
-
"execution_count":
|
530 |
"metadata": {},
|
531 |
"outputs": [],
|
532 |
"source": [
|
@@ -535,6 +608,13 @@
|
|
535 |
"\n",
|
536 |
"final_df.to_json(FULL_PROCESSED_DIR_PATH + \"final.jsonl\", orient=\"records\", lines=True)"
|
537 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
}
|
539 |
],
|
540 |
"metadata": {
|
|
|
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": 47,
|
29 |
"metadata": {},
|
30 |
"outputs": [
|
31 |
{
|
|
|
69 |
" <th>RegionName</th>\n",
|
70 |
" <th>RegionType</th>\n",
|
71 |
" <th>StateName</th>\n",
|
|
|
72 |
" <th>Home Type</th>\n",
|
73 |
" <th>Date</th>\n",
|
74 |
+
" <th>Sale Price</th>\n",
|
75 |
+
" <th>Sale Price per Sqft</th>\n",
|
76 |
+
" <th>Count</th>\n",
|
77 |
" </tr>\n",
|
78 |
" </thead>\n",
|
79 |
" <tbody>\n",
|
|
|
84 |
" <td>United States</td>\n",
|
85 |
" <td>country</td>\n",
|
86 |
" <td>NaN</td>\n",
|
87 |
+
" <td>SFR</td>\n",
|
|
|
88 |
" <td>2018-01-31</td>\n",
|
89 |
+
" <td>309000.0</td>\n",
|
90 |
+
" <td>137.412316</td>\n",
|
91 |
+
" <td>33940.0</td>\n",
|
92 |
" </tr>\n",
|
93 |
" <tr>\n",
|
94 |
" <th>1</th>\n",
|
95 |
+
" <td>102001</td>\n",
|
96 |
+
" <td>0</td>\n",
|
97 |
+
" <td>United States</td>\n",
|
98 |
+
" <td>country</td>\n",
|
99 |
+
" <td>NaN</td>\n",
|
100 |
+
" <td>all homes</td>\n",
|
|
|
101 |
" <td>2018-01-31</td>\n",
|
102 |
+
" <td>314596.0</td>\n",
|
103 |
+
" <td>140.504620</td>\n",
|
104 |
+
" <td>37135.0</td>\n",
|
105 |
" </tr>\n",
|
106 |
" <tr>\n",
|
107 |
" <th>2</th>\n",
|
108 |
+
" <td>102001</td>\n",
|
109 |
+
" <td>0</td>\n",
|
110 |
+
" <td>United States</td>\n",
|
111 |
+
" <td>country</td>\n",
|
112 |
+
" <td>NaN</td>\n",
|
113 |
+
" <td>condo/co-op only</td>\n",
|
|
|
114 |
" <td>2018-01-31</td>\n",
|
115 |
+
" <td>388250.0</td>\n",
|
116 |
+
" <td>238.300000</td>\n",
|
117 |
+
" <td>3195.0</td>\n",
|
118 |
" </tr>\n",
|
119 |
" <tr>\n",
|
120 |
" <th>3</th>\n",
|
121 |
+
" <td>102001</td>\n",
|
122 |
+
" <td>0</td>\n",
|
123 |
+
" <td>United States</td>\n",
|
124 |
+
" <td>country</td>\n",
|
|
|
|
|
|
|
|
|
125 |
" <td>NaN</td>\n",
|
126 |
+
" <td>SFR</td>\n",
|
127 |
+
" <td>2018-02-28</td>\n",
|
128 |
+
" <td>309072.5</td>\n",
|
129 |
+
" <td>137.199170</td>\n",
|
130 |
+
" <td>33304.0</td>\n",
|
131 |
" </tr>\n",
|
132 |
" <tr>\n",
|
133 |
" <th>4</th>\n",
|
134 |
+
" <td>102001</td>\n",
|
135 |
+
" <td>0</td>\n",
|
136 |
+
" <td>United States</td>\n",
|
137 |
+
" <td>country</td>\n",
|
138 |
+
" <td>NaN</td>\n",
|
139 |
+
" <td>all homes</td>\n",
|
140 |
+
" <td>2018-02-28</td>\n",
|
141 |
+
" <td>314608.0</td>\n",
|
142 |
+
" <td>140.304966</td>\n",
|
143 |
+
" <td>36493.0</td>\n",
|
144 |
" </tr>\n",
|
145 |
" <tr>\n",
|
146 |
" <th>...</th>\n",
|
|
|
153 |
" <td>...</td>\n",
|
154 |
" <td>...</td>\n",
|
155 |
" <td>...</td>\n",
|
156 |
+
" <td>...</td>\n",
|
157 |
" </tr>\n",
|
158 |
" <tr>\n",
|
159 |
+
" <th>49482</th>\n",
|
160 |
+
" <td>845162</td>\n",
|
161 |
+
" <td>535</td>\n",
|
162 |
+
" <td>Granbury, TX</td>\n",
|
163 |
" <td>msa</td>\n",
|
164 |
+
" <td>TX</td>\n",
|
165 |
+
" <td>all homes</td>\n",
|
166 |
+
" <td>2023-09-30</td>\n",
|
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",
|
173 |
+
" <td>845162</td>\n",
|
174 |
+
" <td>535</td>\n",
|
175 |
+
" <td>Granbury, TX</td>\n",
|
176 |
" <td>msa</td>\n",
|
177 |
+
" <td>TX</td>\n",
|
178 |
+
" <td>SFR</td>\n",
|
179 |
+
" <td>2023-10-31</td>\n",
|
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",
|
186 |
+
" <td>845162</td>\n",
|
187 |
+
" <td>535</td>\n",
|
188 |
+
" <td>Granbury, TX</td>\n",
|
189 |
" <td>msa</td>\n",
|
190 |
+
" <td>TX</td>\n",
|
191 |
+
" <td>all homes</td>\n",
|
192 |
+
" <td>2023-10-31</td>\n",
|
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",
|
199 |
+
" <td>845162</td>\n",
|
200 |
+
" <td>535</td>\n",
|
201 |
+
" <td>Granbury, TX</td>\n",
|
202 |
" <td>msa</td>\n",
|
203 |
+
" <td>TX</td>\n",
|
204 |
+
" <td>SFR</td>\n",
|
|
|
205 |
" <td>2023-11-30</td>\n",
|
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",
|
212 |
+
" <td>845162</td>\n",
|
213 |
+
" <td>535</td>\n",
|
214 |
+
" <td>Granbury, TX</td>\n",
|
215 |
" <td>msa</td>\n",
|
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",
|
225 |
+
"<p>49487 rows × 10 columns</p>\n",
|
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 Sale Price Sale Price per Sqft Count \n",
|
243 |
+
"0 SFR 2018-01-31 309000.0 137.412316 33940.0 \n",
|
244 |
+
"1 all homes 2018-01-31 314596.0 140.504620 37135.0 \n",
|
245 |
+
"2 condo/co-op only 2018-01-31 388250.0 238.300000 3195.0 \n",
|
246 |
+
"3 SFR 2018-02-28 309072.5 137.199170 33304.0 \n",
|
247 |
+
"4 all homes 2018-02-28 314608.0 140.304966 36493.0 \n",
|
248 |
+
"... ... ... ... ... ... \n",
|
249 |
+
"49482 all homes 2023-09-30 NaN NaN 26.0 \n",
|
250 |
+
"49483 SFR 2023-10-31 NaN NaN 24.0 \n",
|
251 |
+
"49484 all homes 2023-10-31 NaN NaN 24.0 \n",
|
252 |
+
"49485 SFR 2023-11-30 NaN NaN 16.0 \n",
|
253 |
+
"49486 all homes 2023-11-30 NaN NaN 16.0 \n",
|
254 |
"\n",
|
255 |
+
"[49487 rows x 10 columns]"
|
256 |
]
|
257 |
},
|
258 |
+
"execution_count": 47,
|
259 |
"metadata": {},
|
260 |
"output_type": "execute_result"
|
261 |
}
|
|
|
271 |
" \"RegionName\",\n",
|
272 |
" \"RegionType\",\n",
|
273 |
" \"StateName\",\n",
|
274 |
+
" # \"Value Type\",\n",
|
275 |
" \"Home Type\",\n",
|
276 |
"]\n",
|
277 |
"\n",
|
278 |
+
"price_data_frames = []\n",
|
279 |
+
"price_per_sqft_data_frames = []\n",
|
280 |
+
"count_data_frames = []\n",
|
281 |
+
"\n",
|
282 |
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
283 |
" if filename.endswith(\".csv\"):\n",
|
284 |
" print(\"processing \" + filename)\n",
|
285 |
" cur_df = pd.read_csv(os.path.join(FULL_DATA_DIR_PATH, filename))\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
"\n",
|
287 |
" if \"sfrcondo\" in filename:\n",
|
288 |
+
" cur_df[\"Home Type\"] = \"all homes\"\n",
|
289 |
" elif \"sfr\" in filename:\n",
|
290 |
" cur_df[\"Home Type\"] = \"SFR\"\n",
|
291 |
" elif \"condo\" in filename:\n",
|
292 |
+
" cur_df[\"Home Type\"] = \"condo/co-op only\"\n",
|
293 |
"\n",
|
294 |
" # Identify columns to pivot\n",
|
295 |
" columns_to_pivot = [col for col in cur_df.columns if col not in exclude_columns]\n",
|
296 |
"\n",
|
297 |
+
" if \"sale_price_per_sqft\" in filename:\n",
|
298 |
+
" # cur_df[\"Value Type\"] = \"Sale Price Per Sqft\"\n",
|
299 |
+
" # Perform pivot\n",
|
300 |
+
" cur_df = pd.melt(\n",
|
301 |
+
" cur_df,\n",
|
302 |
+
" id_vars=exclude_columns,\n",
|
303 |
+
" value_vars=columns_to_pivot,\n",
|
304 |
+
" var_name=\"Date\",\n",
|
305 |
+
" value_name=\"Sale Price per Sqft\",\n",
|
306 |
+
" )\n",
|
307 |
+
" price_per_sqft_data_frames.append(cur_df)\n",
|
308 |
+
"\n",
|
309 |
+
" elif \"sale_price_uc\" in filename:\n",
|
310 |
+
" # cur_df[\"Value Type\"] = \"Sale Price\"\n",
|
311 |
+
" cur_df = pd.melt(\n",
|
312 |
+
" cur_df,\n",
|
313 |
+
" id_vars=exclude_columns,\n",
|
314 |
+
" value_vars=columns_to_pivot,\n",
|
315 |
+
" var_name=\"Date\",\n",
|
316 |
+
" value_name=\"Sale Price\",\n",
|
317 |
+
" )\n",
|
318 |
+
" price_data_frames.append(cur_df)\n",
|
319 |
+
"\n",
|
320 |
+
" elif \"count\" in filename:\n",
|
321 |
+
" # cur_df[\"Value Type\"] = \"Count\"\n",
|
322 |
+
" cur_df = pd.melt(\n",
|
323 |
+
" cur_df,\n",
|
324 |
+
" id_vars=exclude_columns,\n",
|
325 |
+
" value_vars=columns_to_pivot,\n",
|
326 |
+
" var_name=\"Date\",\n",
|
327 |
+
" value_name=\"Count\",\n",
|
328 |
+
" )\n",
|
329 |
+
" count_data_frames.append(cur_df)\n",
|
330 |
+
"\n",
|
331 |
+
"\n",
|
332 |
+
"combined_price = pd.concat(price_data_frames)\n",
|
333 |
+
"combined_price_per = pd.concat(price_per_sqft_data_frames)\n",
|
334 |
+
"combined_count = pd.concat(count_data_frames)\n",
|
335 |
+
"\n",
|
336 |
+
"matching_cols = [\n",
|
337 |
+
" \"RegionID\",\n",
|
338 |
+
" \"Date\",\n",
|
339 |
+
" \"SizeRank\",\n",
|
340 |
+
" \"RegionName\",\n",
|
341 |
+
" \"RegionType\",\n",
|
342 |
+
" \"StateName\",\n",
|
343 |
+
" # \"Value Type\",\n",
|
344 |
+
" \"Home Type\",\n",
|
345 |
+
"]\n",
|
346 |
"\n",
|
347 |
+
"combined_df = pd.merge(\n",
|
348 |
+
" combined_price,\n",
|
349 |
+
" combined_price_per,\n",
|
350 |
+
" on=matching_cols,\n",
|
351 |
+
" how=\"outer\",\n",
|
352 |
+
")\n",
|
353 |
+
"combined_df = pd.merge(\n",
|
354 |
+
" combined_df,\n",
|
355 |
+
" combined_count,\n",
|
356 |
+
" on=matching_cols,\n",
|
357 |
+
" how=\"outer\",\n",
|
358 |
+
")\n",
|
359 |
"\n",
|
|
|
360 |
"combined_df"
|
361 |
]
|
362 |
},
|
363 |
{
|
364 |
"cell_type": "code",
|
365 |
+
"execution_count": 48,
|
366 |
"metadata": {},
|
367 |
"outputs": [
|
368 |
{
|
|
|
391 |
" <th>Region</th>\n",
|
392 |
" <th>Region Type</th>\n",
|
393 |
" <th>State</th>\n",
|
|
|
394 |
" <th>Home Type</th>\n",
|
395 |
" <th>Date</th>\n",
|
396 |
+
" <th>Sale Price</th>\n",
|
397 |
+
" <th>Sale Price per Sqft</th>\n",
|
398 |
+
" <th>Count</th>\n",
|
399 |
" </tr>\n",
|
400 |
" </thead>\n",
|
401 |
" <tbody>\n",
|
|
|
406 |
" <td>United States</td>\n",
|
407 |
" <td>country</td>\n",
|
408 |
" <td>NaN</td>\n",
|
409 |
+
" <td>SFR</td>\n",
|
|
|
410 |
" <td>2018-01-31</td>\n",
|
411 |
+
" <td>309000.0</td>\n",
|
412 |
+
" <td>137.412316</td>\n",
|
413 |
+
" <td>33940.0</td>\n",
|
414 |
" </tr>\n",
|
415 |
" <tr>\n",
|
416 |
" <th>1</th>\n",
|
417 |
+
" <td>102001</td>\n",
|
418 |
+
" <td>0</td>\n",
|
419 |
+
" <td>United States</td>\n",
|
420 |
+
" <td>country</td>\n",
|
421 |
+
" <td>NaN</td>\n",
|
422 |
+
" <td>all homes</td>\n",
|
|
|
423 |
" <td>2018-01-31</td>\n",
|
424 |
+
" <td>314596.0</td>\n",
|
425 |
+
" <td>140.504620</td>\n",
|
426 |
+
" <td>37135.0</td>\n",
|
427 |
" </tr>\n",
|
428 |
" <tr>\n",
|
429 |
" <th>2</th>\n",
|
430 |
+
" <td>102001</td>\n",
|
431 |
+
" <td>0</td>\n",
|
432 |
+
" <td>United States</td>\n",
|
433 |
+
" <td>country</td>\n",
|
434 |
+
" <td>NaN</td>\n",
|
435 |
+
" <td>condo/co-op only</td>\n",
|
|
|
436 |
" <td>2018-01-31</td>\n",
|
437 |
+
" <td>388250.0</td>\n",
|
438 |
+
" <td>238.300000</td>\n",
|
439 |
+
" <td>3195.0</td>\n",
|
440 |
" </tr>\n",
|
441 |
" <tr>\n",
|
442 |
" <th>3</th>\n",
|
443 |
+
" <td>102001</td>\n",
|
444 |
+
" <td>0</td>\n",
|
445 |
+
" <td>United States</td>\n",
|
446 |
+
" <td>country</td>\n",
|
|
|
|
|
|
|
|
|
447 |
" <td>NaN</td>\n",
|
448 |
+
" <td>SFR</td>\n",
|
449 |
+
" <td>2018-02-28</td>\n",
|
450 |
+
" <td>309072.5</td>\n",
|
451 |
+
" <td>137.199170</td>\n",
|
452 |
+
" <td>33304.0</td>\n",
|
453 |
" </tr>\n",
|
454 |
" <tr>\n",
|
455 |
" <th>4</th>\n",
|
456 |
+
" <td>102001</td>\n",
|
457 |
+
" <td>0</td>\n",
|
458 |
+
" <td>United States</td>\n",
|
459 |
+
" <td>country</td>\n",
|
460 |
+
" <td>NaN</td>\n",
|
461 |
+
" <td>all homes</td>\n",
|
462 |
+
" <td>2018-02-28</td>\n",
|
463 |
+
" <td>314608.0</td>\n",
|
464 |
+
" <td>140.304966</td>\n",
|
465 |
+
" <td>36493.0</td>\n",
|
466 |
" </tr>\n",
|
467 |
" <tr>\n",
|
468 |
" <th>...</th>\n",
|
|
|
475 |
" <td>...</td>\n",
|
476 |
" <td>...</td>\n",
|
477 |
" <td>...</td>\n",
|
478 |
+
" <td>...</td>\n",
|
479 |
" </tr>\n",
|
480 |
" <tr>\n",
|
481 |
+
" <th>49482</th>\n",
|
482 |
+
" <td>845162</td>\n",
|
483 |
+
" <td>535</td>\n",
|
484 |
+
" <td>Granbury, TX</td>\n",
|
485 |
" <td>msa</td>\n",
|
486 |
+
" <td>TX</td>\n",
|
487 |
+
" <td>all homes</td>\n",
|
488 |
+
" <td>2023-09-30</td>\n",
|
489 |
+
" <td>NaN</td>\n",
|
490 |
+
" <td>NaN</td>\n",
|
491 |
+
" <td>26.0</td>\n",
|
492 |
" </tr>\n",
|
493 |
" <tr>\n",
|
494 |
+
" <th>49483</th>\n",
|
495 |
+
" <td>845162</td>\n",
|
496 |
+
" <td>535</td>\n",
|
497 |
+
" <td>Granbury, TX</td>\n",
|
498 |
" <td>msa</td>\n",
|
499 |
+
" <td>TX</td>\n",
|
500 |
+
" <td>SFR</td>\n",
|
501 |
+
" <td>2023-10-31</td>\n",
|
502 |
+
" <td>NaN</td>\n",
|
503 |
+
" <td>NaN</td>\n",
|
504 |
+
" <td>24.0</td>\n",
|
505 |
" </tr>\n",
|
506 |
" <tr>\n",
|
507 |
+
" <th>49484</th>\n",
|
508 |
+
" <td>845162</td>\n",
|
509 |
+
" <td>535</td>\n",
|
510 |
+
" <td>Granbury, TX</td>\n",
|
511 |
" <td>msa</td>\n",
|
512 |
+
" <td>TX</td>\n",
|
513 |
+
" <td>all homes</td>\n",
|
514 |
+
" <td>2023-10-31</td>\n",
|
515 |
+
" <td>NaN</td>\n",
|
516 |
+
" <td>NaN</td>\n",
|
517 |
+
" <td>24.0</td>\n",
|
518 |
" </tr>\n",
|
519 |
" <tr>\n",
|
520 |
+
" <th>49485</th>\n",
|
521 |
+
" <td>845162</td>\n",
|
522 |
+
" <td>535</td>\n",
|
523 |
+
" <td>Granbury, TX</td>\n",
|
524 |
" <td>msa</td>\n",
|
525 |
+
" <td>TX</td>\n",
|
526 |
+
" <td>SFR</td>\n",
|
|
|
527 |
" <td>2023-11-30</td>\n",
|
528 |
+
" <td>NaN</td>\n",
|
529 |
+
" <td>NaN</td>\n",
|
530 |
+
" <td>16.0</td>\n",
|
531 |
" </tr>\n",
|
532 |
" <tr>\n",
|
533 |
+
" <th>49486</th>\n",
|
534 |
+
" <td>845162</td>\n",
|
535 |
+
" <td>535</td>\n",
|
536 |
+
" <td>Granbury, TX</td>\n",
|
537 |
" <td>msa</td>\n",
|
538 |
+
" <td>TX</td>\n",
|
539 |
+
" <td>all homes</td>\n",
|
|
|
540 |
" <td>2023-11-30</td>\n",
|
541 |
+
" <td>NaN</td>\n",
|
542 |
+
" <td>NaN</td>\n",
|
543 |
+
" <td>16.0</td>\n",
|
544 |
" </tr>\n",
|
545 |
" </tbody>\n",
|
546 |
"</table>\n",
|
547 |
+
"<p>49487 rows × 10 columns</p>\n",
|
548 |
"</div>"
|
549 |
],
|
550 |
"text/plain": [
|
551 |
+
" Region ID Size Rank Region Region Type State \\\n",
|
552 |
+
"0 102001 0 United States country NaN \n",
|
553 |
+
"1 102001 0 United States country NaN \n",
|
554 |
+
"2 102001 0 United States country NaN \n",
|
555 |
+
"3 102001 0 United States country NaN \n",
|
556 |
+
"4 102001 0 United States country NaN \n",
|
557 |
+
"... ... ... ... ... ... \n",
|
558 |
+
"49482 845162 535 Granbury, TX msa TX \n",
|
559 |
+
"49483 845162 535 Granbury, TX msa TX \n",
|
560 |
+
"49484 845162 535 Granbury, TX msa TX \n",
|
561 |
+
"49485 845162 535 Granbury, TX msa TX \n",
|
562 |
+
"49486 845162 535 Granbury, TX msa TX \n",
|
563 |
"\n",
|
564 |
+
" Home Type Date Sale Price Sale Price per Sqft Count \n",
|
565 |
+
"0 SFR 2018-01-31 309000.0 137.412316 33940.0 \n",
|
566 |
+
"1 all homes 2018-01-31 314596.0 140.504620 37135.0 \n",
|
567 |
+
"2 condo/co-op only 2018-01-31 388250.0 238.300000 3195.0 \n",
|
568 |
+
"3 SFR 2018-02-28 309072.5 137.199170 33304.0 \n",
|
569 |
+
"4 all homes 2018-02-28 314608.0 140.304966 36493.0 \n",
|
570 |
+
"... ... ... ... ... ... \n",
|
571 |
+
"49482 all homes 2023-09-30 NaN NaN 26.0 \n",
|
572 |
+
"49483 SFR 2023-10-31 NaN NaN 24.0 \n",
|
573 |
+
"49484 all homes 2023-10-31 NaN NaN 24.0 \n",
|
574 |
+
"49485 SFR 2023-11-30 NaN NaN 16.0 \n",
|
575 |
+
"49486 all homes 2023-11-30 NaN NaN 16.0 \n",
|
576 |
"\n",
|
577 |
+
"[49487 rows x 10 columns]"
|
578 |
]
|
579 |
},
|
580 |
+
"execution_count": 48,
|
581 |
"metadata": {},
|
582 |
"output_type": "execute_result"
|
583 |
}
|
|
|
599 |
},
|
600 |
{
|
601 |
"cell_type": "code",
|
602 |
+
"execution_count": 49,
|
603 |
"metadata": {},
|
604 |
"outputs": [],
|
605 |
"source": [
|
|
|
608 |
"\n",
|
609 |
"final_df.to_json(FULL_PROCESSED_DIR_PATH + \"final.jsonl\", orient=\"records\", lines=True)"
|
610 |
]
|
611 |
+
},
|
612 |
+
{
|
613 |
+
"cell_type": "code",
|
614 |
+
"execution_count": null,
|
615 |
+
"metadata": {},
|
616 |
+
"outputs": [],
|
617 |
+
"source": []
|
618 |
}
|
619 |
],
|
620 |
"metadata": {
|
zillow.py
CHANGED
@@ -133,7 +133,11 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
133 |
"Value Type": datasets.Value(dtype="string", id="Value Type"),
|
134 |
"Home Type": datasets.Value(dtype="string", id="Home Type"),
|
135 |
"Date": datasets.Value(dtype="string", id="Date"),
|
136 |
-
"
|
|
|
|
|
|
|
|
|
137 |
# These are the features of your dataset like images, labels ...
|
138 |
}
|
139 |
)
|
@@ -253,7 +257,9 @@ class NewDataset(datasets.GeneratorBasedBuilder):
|
|
253 |
"Value Type": data["Value Type"],
|
254 |
"Home Type": data["Home Type"],
|
255 |
"Date": data["Date"],
|
256 |
-
"
|
|
|
|
|
257 |
# "answer": "" if split == "test" else data["answer"],
|
258 |
}
|
259 |
# else:
|
|
|
133 |
"Value Type": datasets.Value(dtype="string", id="Value Type"),
|
134 |
"Home Type": datasets.Value(dtype="string", id="Home Type"),
|
135 |
"Date": datasets.Value(dtype="string", id="Date"),
|
136 |
+
"Sale Price": datasets.Value(dtype="float32", id="Sale Price"),
|
137 |
+
"Sale Price per Sqft": datasets.Value(
|
138 |
+
dtype="float32", id="Sale Price per Sqft"
|
139 |
+
),
|
140 |
+
"Count": datasets.Value(dtype="int32", id="Count"),
|
141 |
# These are the features of your dataset like images, labels ...
|
142 |
}
|
143 |
)
|
|
|
257 |
"Value Type": data["Value Type"],
|
258 |
"Home Type": data["Home Type"],
|
259 |
"Date": data["Date"],
|
260 |
+
"Sale Price": data["Sale Price"],
|
261 |
+
"Sale Price per Sqft": data["Sale Price per Sqft"],
|
262 |
+
"Count": data["Count"],
|
263 |
# "answer": "" if split == "test" else data["answer"],
|
264 |
}
|
265 |
# else:
|