feat: process home value forecasts into a single csv
Browse files- .gitignore +0 -0
- .vscode/settings.json +3 -2
- process_home_value_forecasts.ipynb +800 -0
- processed/home_value_forecasts/final.csv +0 -0
.gitignore
ADDED
File without changes
|
.vscode/settings.json
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
"[python]": {
|
3 |
"editor.defaultFormatter": "ms-python.black-formatter",
|
4 |
"editor.formatOnSave": true
|
5 |
-
}
|
|
|
|
|
6 |
}
|
7 |
-
|
|
|
2 |
"[python]": {
|
3 |
"editor.defaultFormatter": "ms-python.black-formatter",
|
4 |
"editor.formatOnSave": true
|
5 |
+
},
|
6 |
+
"python.analysis.autoImportCompletions": true,
|
7 |
+
"python.analysis.typeCheckingMode": "basic"
|
8 |
}
|
|
process_home_value_forecasts.ipynb
ADDED
@@ -0,0 +1,800 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 22,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"import pandas as pd\n",
|
10 |
+
"import os"
|
11 |
+
]
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"cell_type": "code",
|
15 |
+
"execution_count": 23,
|
16 |
+
"metadata": {},
|
17 |
+
"outputs": [],
|
18 |
+
"source": [
|
19 |
+
"DATA_DIR = 'data/'\n",
|
20 |
+
"PROCESSED_DIR = 'processed/'\n",
|
21 |
+
"FACET_DIR = 'home_value_forecasts/'\n",
|
22 |
+
"FULL_DATA_DIR_PATH = DATA_DIR + FACET_DIR\n",
|
23 |
+
"FULL_PROCESSED_DIR_PATH = PROCESSED_DIR + FACET_DIR"
|
24 |
+
]
|
25 |
+
},
|
26 |
+
{
|
27 |
+
"cell_type": "code",
|
28 |
+
"execution_count": 24,
|
29 |
+
"metadata": {},
|
30 |
+
"outputs": [
|
31 |
+
{
|
32 |
+
"name": "stdout",
|
33 |
+
"output_type": "stream",
|
34 |
+
"text": [
|
35 |
+
"processing Zip_zhvf_growth_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n",
|
36 |
+
"processing Metro_zhvf_growth_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv\n",
|
37 |
+
"processing Zip_zhvf_growth_uc_sfrcondo_tier_0.33_0.67_month.csv\n",
|
38 |
+
"processing Metro_zhvf_growth_uc_sfrcondo_tier_0.33_0.67_month.csv\n"
|
39 |
+
]
|
40 |
+
},
|
41 |
+
{
|
42 |
+
"data": {
|
43 |
+
"text/html": [
|
44 |
+
"<div>\n",
|
45 |
+
"<style scoped>\n",
|
46 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
47 |
+
" vertical-align: middle;\n",
|
48 |
+
" }\n",
|
49 |
+
"\n",
|
50 |
+
" .dataframe tbody tr th {\n",
|
51 |
+
" vertical-align: top;\n",
|
52 |
+
" }\n",
|
53 |
+
"\n",
|
54 |
+
" .dataframe thead th {\n",
|
55 |
+
" text-align: right;\n",
|
56 |
+
" }\n",
|
57 |
+
"</style>\n",
|
58 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
59 |
+
" <thead>\n",
|
60 |
+
" <tr style=\"text-align: right;\">\n",
|
61 |
+
" <th></th>\n",
|
62 |
+
" <th>RegionID</th>\n",
|
63 |
+
" <th>SizeRank</th>\n",
|
64 |
+
" <th>RegionName</th>\n",
|
65 |
+
" <th>RegionType</th>\n",
|
66 |
+
" <th>StateName</th>\n",
|
67 |
+
" <th>BaseDate</th>\n",
|
68 |
+
" <th>Month Over Month % (Smoothed)</th>\n",
|
69 |
+
" <th>Quarter Over Quarter % (Smoothed)</th>\n",
|
70 |
+
" <th>Year Over Year % (Smoothed)</th>\n",
|
71 |
+
" <th>Month Over Month % (Raw)</th>\n",
|
72 |
+
" <th>Quarter Over Quarter % (Raw)</th>\n",
|
73 |
+
" <th>Year Over Year % (Raw)</th>\n",
|
74 |
+
" <th>State</th>\n",
|
75 |
+
" <th>City</th>\n",
|
76 |
+
" <th>Metro</th>\n",
|
77 |
+
" <th>CountyName</th>\n",
|
78 |
+
" </tr>\n",
|
79 |
+
" </thead>\n",
|
80 |
+
" <tbody>\n",
|
81 |
+
" <tr>\n",
|
82 |
+
" <th>0</th>\n",
|
83 |
+
" <td>102001</td>\n",
|
84 |
+
" <td>0</td>\n",
|
85 |
+
" <td>United States</td>\n",
|
86 |
+
" <td>country</td>\n",
|
87 |
+
" <td>NaN</td>\n",
|
88 |
+
" <td>2023-12-31</td>\n",
|
89 |
+
" <td>0.1</td>\n",
|
90 |
+
" <td>0.4</td>\n",
|
91 |
+
" <td>3.5</td>\n",
|
92 |
+
" <td>-0.5</td>\n",
|
93 |
+
" <td>0.4</td>\n",
|
94 |
+
" <td>3.7</td>\n",
|
95 |
+
" <td>NaN</td>\n",
|
96 |
+
" <td>NaN</td>\n",
|
97 |
+
" <td>NaN</td>\n",
|
98 |
+
" <td>NaN</td>\n",
|
99 |
+
" </tr>\n",
|
100 |
+
" <tr>\n",
|
101 |
+
" <th>1</th>\n",
|
102 |
+
" <td>394913</td>\n",
|
103 |
+
" <td>1</td>\n",
|
104 |
+
" <td>New York, NY</td>\n",
|
105 |
+
" <td>msa</td>\n",
|
106 |
+
" <td>NY</td>\n",
|
107 |
+
" <td>2023-12-31</td>\n",
|
108 |
+
" <td>0.2</td>\n",
|
109 |
+
" <td>0.2</td>\n",
|
110 |
+
" <td>1.0</td>\n",
|
111 |
+
" <td>-0.7</td>\n",
|
112 |
+
" <td>-0.9</td>\n",
|
113 |
+
" <td>0.6</td>\n",
|
114 |
+
" <td>NaN</td>\n",
|
115 |
+
" <td>NaN</td>\n",
|
116 |
+
" <td>NaN</td>\n",
|
117 |
+
" <td>NaN</td>\n",
|
118 |
+
" </tr>\n",
|
119 |
+
" <tr>\n",
|
120 |
+
" <th>2</th>\n",
|
121 |
+
" <td>753899</td>\n",
|
122 |
+
" <td>2</td>\n",
|
123 |
+
" <td>Los Angeles, CA</td>\n",
|
124 |
+
" <td>msa</td>\n",
|
125 |
+
" <td>CA</td>\n",
|
126 |
+
" <td>2023-12-31</td>\n",
|
127 |
+
" <td>-0.1</td>\n",
|
128 |
+
" <td>-1.8</td>\n",
|
129 |
+
" <td>0.7</td>\n",
|
130 |
+
" <td>-0.6</td>\n",
|
131 |
+
" <td>0.8</td>\n",
|
132 |
+
" <td>1.4</td>\n",
|
133 |
+
" <td>NaN</td>\n",
|
134 |
+
" <td>NaN</td>\n",
|
135 |
+
" <td>NaN</td>\n",
|
136 |
+
" <td>NaN</td>\n",
|
137 |
+
" </tr>\n",
|
138 |
+
" <tr>\n",
|
139 |
+
" <th>3</th>\n",
|
140 |
+
" <td>394463</td>\n",
|
141 |
+
" <td>3</td>\n",
|
142 |
+
" <td>Chicago, IL</td>\n",
|
143 |
+
" <td>msa</td>\n",
|
144 |
+
" <td>IL</td>\n",
|
145 |
+
" <td>2023-12-31</td>\n",
|
146 |
+
" <td>0.1</td>\n",
|
147 |
+
" <td>0.4</td>\n",
|
148 |
+
" <td>1.6</td>\n",
|
149 |
+
" <td>-0.8</td>\n",
|
150 |
+
" <td>-0.2</td>\n",
|
151 |
+
" <td>1.4</td>\n",
|
152 |
+
" <td>NaN</td>\n",
|
153 |
+
" <td>NaN</td>\n",
|
154 |
+
" <td>NaN</td>\n",
|
155 |
+
" <td>NaN</td>\n",
|
156 |
+
" </tr>\n",
|
157 |
+
" <tr>\n",
|
158 |
+
" <th>4</th>\n",
|
159 |
+
" <td>394514</td>\n",
|
160 |
+
" <td>4</td>\n",
|
161 |
+
" <td>Dallas, TX</td>\n",
|
162 |
+
" <td>msa</td>\n",
|
163 |
+
" <td>TX</td>\n",
|
164 |
+
" <td>2023-12-31</td>\n",
|
165 |
+
" <td>-0.1</td>\n",
|
166 |
+
" <td>0.0</td>\n",
|
167 |
+
" <td>3.2</td>\n",
|
168 |
+
" <td>-0.6</td>\n",
|
169 |
+
" <td>0.9</td>\n",
|
170 |
+
" <td>3.6</td>\n",
|
171 |
+
" <td>NaN</td>\n",
|
172 |
+
" <td>NaN</td>\n",
|
173 |
+
" <td>NaN</td>\n",
|
174 |
+
" <td>NaN</td>\n",
|
175 |
+
" </tr>\n",
|
176 |
+
" <tr>\n",
|
177 |
+
" <th>...</th>\n",
|
178 |
+
" <td>...</td>\n",
|
179 |
+
" <td>...</td>\n",
|
180 |
+
" <td>...</td>\n",
|
181 |
+
" <td>...</td>\n",
|
182 |
+
" <td>...</td>\n",
|
183 |
+
" <td>...</td>\n",
|
184 |
+
" <td>...</td>\n",
|
185 |
+
" <td>...</td>\n",
|
186 |
+
" <td>...</td>\n",
|
187 |
+
" <td>...</td>\n",
|
188 |
+
" <td>...</td>\n",
|
189 |
+
" <td>...</td>\n",
|
190 |
+
" <td>...</td>\n",
|
191 |
+
" <td>...</td>\n",
|
192 |
+
" <td>...</td>\n",
|
193 |
+
" <td>...</td>\n",
|
194 |
+
" </tr>\n",
|
195 |
+
" <tr>\n",
|
196 |
+
" <th>20162</th>\n",
|
197 |
+
" <td>82097</td>\n",
|
198 |
+
" <td>39992</td>\n",
|
199 |
+
" <td>55087</td>\n",
|
200 |
+
" <td>zip</td>\n",
|
201 |
+
" <td>MN</td>\n",
|
202 |
+
" <td>2023-12-31</td>\n",
|
203 |
+
" <td>0.1</td>\n",
|
204 |
+
" <td>0.7</td>\n",
|
205 |
+
" <td>1.8</td>\n",
|
206 |
+
" <td>-0.9</td>\n",
|
207 |
+
" <td>-0.2</td>\n",
|
208 |
+
" <td>2.6</td>\n",
|
209 |
+
" <td>MN</td>\n",
|
210 |
+
" <td>Warsaw</td>\n",
|
211 |
+
" <td>Faribault-Northfield, MN</td>\n",
|
212 |
+
" <td>Rice County</td>\n",
|
213 |
+
" </tr>\n",
|
214 |
+
" <tr>\n",
|
215 |
+
" <th>20163</th>\n",
|
216 |
+
" <td>85325</td>\n",
|
217 |
+
" <td>39992</td>\n",
|
218 |
+
" <td>62093</td>\n",
|
219 |
+
" <td>zip</td>\n",
|
220 |
+
" <td>IL</td>\n",
|
221 |
+
" <td>2023-12-31</td>\n",
|
222 |
+
" <td>0.9</td>\n",
|
223 |
+
" <td>0.4</td>\n",
|
224 |
+
" <td>3.7</td>\n",
|
225 |
+
" <td>-0.7</td>\n",
|
226 |
+
" <td>0.4</td>\n",
|
227 |
+
" <td>2.3</td>\n",
|
228 |
+
" <td>IL</td>\n",
|
229 |
+
" <td>NaN</td>\n",
|
230 |
+
" <td>St. Louis, MO-IL</td>\n",
|
231 |
+
" <td>Macoupin County</td>\n",
|
232 |
+
" </tr>\n",
|
233 |
+
" <tr>\n",
|
234 |
+
" <th>20164</th>\n",
|
235 |
+
" <td>92085</td>\n",
|
236 |
+
" <td>39992</td>\n",
|
237 |
+
" <td>77661</td>\n",
|
238 |
+
" <td>zip</td>\n",
|
239 |
+
" <td>TX</td>\n",
|
240 |
+
" <td>2023-12-31</td>\n",
|
241 |
+
" <td>-0.5</td>\n",
|
242 |
+
" <td>0.3</td>\n",
|
243 |
+
" <td>-0.6</td>\n",
|
244 |
+
" <td>-0.4</td>\n",
|
245 |
+
" <td>0.0</td>\n",
|
246 |
+
" <td>1.2</td>\n",
|
247 |
+
" <td>TX</td>\n",
|
248 |
+
" <td>NaN</td>\n",
|
249 |
+
" <td>Houston-The Woodlands-Sugar Land, TX</td>\n",
|
250 |
+
" <td>Chambers County</td>\n",
|
251 |
+
" </tr>\n",
|
252 |
+
" <tr>\n",
|
253 |
+
" <th>20165</th>\n",
|
254 |
+
" <td>92811</td>\n",
|
255 |
+
" <td>39992</td>\n",
|
256 |
+
" <td>79078</td>\n",
|
257 |
+
" <td>zip</td>\n",
|
258 |
+
" <td>TX</td>\n",
|
259 |
+
" <td>2023-12-31</td>\n",
|
260 |
+
" <td>-1.2</td>\n",
|
261 |
+
" <td>-1.1</td>\n",
|
262 |
+
" <td>-3.1</td>\n",
|
263 |
+
" <td>-1.7</td>\n",
|
264 |
+
" <td>-2.6</td>\n",
|
265 |
+
" <td>-1.9</td>\n",
|
266 |
+
" <td>TX</td>\n",
|
267 |
+
" <td>NaN</td>\n",
|
268 |
+
" <td>Borger, TX</td>\n",
|
269 |
+
" <td>Hutchinson County</td>\n",
|
270 |
+
" </tr>\n",
|
271 |
+
" <tr>\n",
|
272 |
+
" <th>20166</th>\n",
|
273 |
+
" <td>98183</td>\n",
|
274 |
+
" <td>39992</td>\n",
|
275 |
+
" <td>95419</td>\n",
|
276 |
+
" <td>zip</td>\n",
|
277 |
+
" <td>CA</td>\n",
|
278 |
+
" <td>2023-12-31</td>\n",
|
279 |
+
" <td>-0.5</td>\n",
|
280 |
+
" <td>-0.2</td>\n",
|
281 |
+
" <td>0.0</td>\n",
|
282 |
+
" <td>-0.5</td>\n",
|
283 |
+
" <td>0.6</td>\n",
|
284 |
+
" <td>-0.4</td>\n",
|
285 |
+
" <td>CA</td>\n",
|
286 |
+
" <td>Camp Meeker</td>\n",
|
287 |
+
" <td>Santa Rosa-Petaluma, CA</td>\n",
|
288 |
+
" <td>Sonoma County</td>\n",
|
289 |
+
" </tr>\n",
|
290 |
+
" </tbody>\n",
|
291 |
+
"</table>\n",
|
292 |
+
"<p>21062 rows × 16 columns</p>\n",
|
293 |
+
"</div>"
|
294 |
+
],
|
295 |
+
"text/plain": [
|
296 |
+
" RegionID SizeRank RegionName RegionType StateName BaseDate \\\n",
|
297 |
+
"0 102001 0 United States country NaN 2023-12-31 \n",
|
298 |
+
"1 394913 1 New York, NY msa NY 2023-12-31 \n",
|
299 |
+
"2 753899 2 Los Angeles, CA msa CA 2023-12-31 \n",
|
300 |
+
"3 394463 3 Chicago, IL msa IL 2023-12-31 \n",
|
301 |
+
"4 394514 4 Dallas, TX msa TX 2023-12-31 \n",
|
302 |
+
"... ... ... ... ... ... ... \n",
|
303 |
+
"20162 82097 39992 55087 zip MN 2023-12-31 \n",
|
304 |
+
"20163 85325 39992 62093 zip IL 2023-12-31 \n",
|
305 |
+
"20164 92085 39992 77661 zip TX 2023-12-31 \n",
|
306 |
+
"20165 92811 39992 79078 zip TX 2023-12-31 \n",
|
307 |
+
"20166 98183 39992 95419 zip CA 2023-12-31 \n",
|
308 |
+
"\n",
|
309 |
+
" Month Over Month % (Smoothed) Quarter Over Quarter % (Smoothed) \\\n",
|
310 |
+
"0 0.1 0.4 \n",
|
311 |
+
"1 0.2 0.2 \n",
|
312 |
+
"2 -0.1 -1.8 \n",
|
313 |
+
"3 0.1 0.4 \n",
|
314 |
+
"4 -0.1 0.0 \n",
|
315 |
+
"... ... ... \n",
|
316 |
+
"20162 0.1 0.7 \n",
|
317 |
+
"20163 0.9 0.4 \n",
|
318 |
+
"20164 -0.5 0.3 \n",
|
319 |
+
"20165 -1.2 -1.1 \n",
|
320 |
+
"20166 -0.5 -0.2 \n",
|
321 |
+
"\n",
|
322 |
+
" Year Over Year % (Smoothed) Month Over Month % (Raw) \\\n",
|
323 |
+
"0 3.5 -0.5 \n",
|
324 |
+
"1 1.0 -0.7 \n",
|
325 |
+
"2 0.7 -0.6 \n",
|
326 |
+
"3 1.6 -0.8 \n",
|
327 |
+
"4 3.2 -0.6 \n",
|
328 |
+
"... ... ... \n",
|
329 |
+
"20162 1.8 -0.9 \n",
|
330 |
+
"20163 3.7 -0.7 \n",
|
331 |
+
"20164 -0.6 -0.4 \n",
|
332 |
+
"20165 -3.1 -1.7 \n",
|
333 |
+
"20166 0.0 -0.5 \n",
|
334 |
+
"\n",
|
335 |
+
" Quarter Over Quarter % (Raw) Year Over Year % (Raw) State \\\n",
|
336 |
+
"0 0.4 3.7 NaN \n",
|
337 |
+
"1 -0.9 0.6 NaN \n",
|
338 |
+
"2 0.8 1.4 NaN \n",
|
339 |
+
"3 -0.2 1.4 NaN \n",
|
340 |
+
"4 0.9 3.6 NaN \n",
|
341 |
+
"... ... ... ... \n",
|
342 |
+
"20162 -0.2 2.6 MN \n",
|
343 |
+
"20163 0.4 2.3 IL \n",
|
344 |
+
"20164 0.0 1.2 TX \n",
|
345 |
+
"20165 -2.6 -1.9 TX \n",
|
346 |
+
"20166 0.6 -0.4 CA \n",
|
347 |
+
"\n",
|
348 |
+
" City Metro CountyName \n",
|
349 |
+
"0 NaN NaN NaN \n",
|
350 |
+
"1 NaN NaN NaN \n",
|
351 |
+
"2 NaN NaN NaN \n",
|
352 |
+
"3 NaN NaN NaN \n",
|
353 |
+
"4 NaN NaN NaN \n",
|
354 |
+
"... ... ... ... \n",
|
355 |
+
"20162 Warsaw Faribault-Northfield, MN Rice County \n",
|
356 |
+
"20163 NaN St. Louis, MO-IL Macoupin County \n",
|
357 |
+
"20164 NaN Houston-The Woodlands-Sugar Land, TX Chambers County \n",
|
358 |
+
"20165 NaN Borger, TX Hutchinson County \n",
|
359 |
+
"20166 Camp Meeker Santa Rosa-Petaluma, CA Sonoma County \n",
|
360 |
+
"\n",
|
361 |
+
"[21062 rows x 16 columns]"
|
362 |
+
]
|
363 |
+
},
|
364 |
+
"execution_count": 24,
|
365 |
+
"metadata": {},
|
366 |
+
"output_type": "execute_result"
|
367 |
+
}
|
368 |
+
],
|
369 |
+
"source": [
|
370 |
+
"metro_data_frames = []\n",
|
371 |
+
"zip_data_frames = []\n",
|
372 |
+
"for filename in os.listdir(FULL_DATA_DIR_PATH):\n",
|
373 |
+
" if filename.endswith('.csv'):\n",
|
374 |
+
" print('processing ' + filename)\n",
|
375 |
+
" cur_df = pd.read_csv(FULL_DATA_DIR_PATH + filename)\n",
|
376 |
+
" \n",
|
377 |
+
" cols = ['Month Over Month %', 'Quarter Over Quarter %', 'Year Over Year %']\n",
|
378 |
+
" if (filename.endswith('sm_sa_month.csv')):\n",
|
379 |
+
" # print('Smoothed')\n",
|
380 |
+
" cur_df.columns = list(cur_df.columns[:-3]) + [x + ' (Smoothed)' for x in cols]\n",
|
381 |
+
" else:\n",
|
382 |
+
" # print('Raw')\n",
|
383 |
+
" cur_df.columns = list(cur_df.columns[:-3]) + [x + ' (Raw)' for x in cols]\n",
|
384 |
+
" \n",
|
385 |
+
" if (filename.startswith('Metro')):\n",
|
386 |
+
" # print('Metro')\n",
|
387 |
+
" metro_data_frames.append(cur_df)\n",
|
388 |
+
"\n",
|
389 |
+
" elif (filename.startswith('Zip')):\n",
|
390 |
+
" # print('Zip')\n",
|
391 |
+
" zip_data_frames.append(cur_df)\n",
|
392 |
+
"\n",
|
393 |
+
"def get_combined_df(data_frames):\n",
|
394 |
+
" combined_df = None\n",
|
395 |
+
" if len(data_frames) > 1:\n",
|
396 |
+
" # iterate over dataframes and merge them\n",
|
397 |
+
" final_df = data_frames[0]\n",
|
398 |
+
" for i in range(1, len(data_frames)):\n",
|
399 |
+
" cur_df = data_frames[i]\n",
|
400 |
+
" cols = list(cur_df.columns[-3:])\n",
|
401 |
+
" cols.append('RegionID')\n",
|
402 |
+
" combined_df = pd.merge(final_df, cur_df[cols], on='RegionID')\n",
|
403 |
+
" elif len(data_frames) == 1:\n",
|
404 |
+
" combined_df = data_frames[0]\n",
|
405 |
+
" \n",
|
406 |
+
" \n",
|
407 |
+
" return(combined_df)\n",
|
408 |
+
"\n",
|
409 |
+
"combined_metro_dfs = get_combined_df(metro_data_frames)\n",
|
410 |
+
"combined_zip_dfs = get_combined_df(zip_data_frames)\n",
|
411 |
+
"\n",
|
412 |
+
"combined_df = pd.concat([combined_metro_dfs, combined_zip_dfs])\n",
|
413 |
+
"combined_df"
|
414 |
+
]
|
415 |
+
},
|
416 |
+
{
|
417 |
+
"cell_type": "code",
|
418 |
+
"execution_count": 34,
|
419 |
+
"metadata": {},
|
420 |
+
"outputs": [
|
421 |
+
{
|
422 |
+
"data": {
|
423 |
+
"text/html": [
|
424 |
+
"<div>\n",
|
425 |
+
"<style scoped>\n",
|
426 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
427 |
+
" vertical-align: middle;\n",
|
428 |
+
" }\n",
|
429 |
+
"\n",
|
430 |
+
" .dataframe tbody tr th {\n",
|
431 |
+
" vertical-align: top;\n",
|
432 |
+
" }\n",
|
433 |
+
"\n",
|
434 |
+
" .dataframe thead th {\n",
|
435 |
+
" text-align: right;\n",
|
436 |
+
" }\n",
|
437 |
+
"</style>\n",
|
438 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
439 |
+
" <thead>\n",
|
440 |
+
" <tr style=\"text-align: right;\">\n",
|
441 |
+
" <th></th>\n",
|
442 |
+
" <th>RegionID</th>\n",
|
443 |
+
" <th>RegionName</th>\n",
|
444 |
+
" <th>RegionType</th>\n",
|
445 |
+
" <th>SizeRank</th>\n",
|
446 |
+
" <th>State</th>\n",
|
447 |
+
" <th>City</th>\n",
|
448 |
+
" <th>Metro</th>\n",
|
449 |
+
" <th>CountyName</th>\n",
|
450 |
+
" <th>BaseDate</th>\n",
|
451 |
+
" <th>Month Over Month % (Smoothed)</th>\n",
|
452 |
+
" <th>Quarter Over Quarter % (Smoothed)</th>\n",
|
453 |
+
" <th>Year Over Year % (Smoothed)</th>\n",
|
454 |
+
" <th>Month Over Month % (Raw)</th>\n",
|
455 |
+
" <th>Quarter Over Quarter % (Raw)</th>\n",
|
456 |
+
" <th>Year Over Year % (Raw)</th>\n",
|
457 |
+
" </tr>\n",
|
458 |
+
" </thead>\n",
|
459 |
+
" <tbody>\n",
|
460 |
+
" <tr>\n",
|
461 |
+
" <th>0</th>\n",
|
462 |
+
" <td>102001</td>\n",
|
463 |
+
" <td>United States</td>\n",
|
464 |
+
" <td>country</td>\n",
|
465 |
+
" <td>0</td>\n",
|
466 |
+
" <td>NaN</td>\n",
|
467 |
+
" <td>NaN</td>\n",
|
468 |
+
" <td>NaN</td>\n",
|
469 |
+
" <td>NaN</td>\n",
|
470 |
+
" <td>2023-12-31</td>\n",
|
471 |
+
" <td>0.1</td>\n",
|
472 |
+
" <td>0.4</td>\n",
|
473 |
+
" <td>3.5</td>\n",
|
474 |
+
" <td>-0.5</td>\n",
|
475 |
+
" <td>0.4</td>\n",
|
476 |
+
" <td>3.7</td>\n",
|
477 |
+
" </tr>\n",
|
478 |
+
" <tr>\n",
|
479 |
+
" <th>1</th>\n",
|
480 |
+
" <td>394913</td>\n",
|
481 |
+
" <td>New York, NY</td>\n",
|
482 |
+
" <td>msa</td>\n",
|
483 |
+
" <td>1</td>\n",
|
484 |
+
" <td>NY</td>\n",
|
485 |
+
" <td>New York</td>\n",
|
486 |
+
" <td>New York, NY</td>\n",
|
487 |
+
" <td>NaN</td>\n",
|
488 |
+
" <td>2023-12-31</td>\n",
|
489 |
+
" <td>0.2</td>\n",
|
490 |
+
" <td>0.2</td>\n",
|
491 |
+
" <td>1.0</td>\n",
|
492 |
+
" <td>-0.7</td>\n",
|
493 |
+
" <td>-0.9</td>\n",
|
494 |
+
" <td>0.6</td>\n",
|
495 |
+
" </tr>\n",
|
496 |
+
" <tr>\n",
|
497 |
+
" <th>2</th>\n",
|
498 |
+
" <td>753899</td>\n",
|
499 |
+
" <td>Los Angeles, CA</td>\n",
|
500 |
+
" <td>msa</td>\n",
|
501 |
+
" <td>2</td>\n",
|
502 |
+
" <td>CA</td>\n",
|
503 |
+
" <td>Los Angeles</td>\n",
|
504 |
+
" <td>Los Angeles, CA</td>\n",
|
505 |
+
" <td>NaN</td>\n",
|
506 |
+
" <td>2023-12-31</td>\n",
|
507 |
+
" <td>-0.1</td>\n",
|
508 |
+
" <td>-1.8</td>\n",
|
509 |
+
" <td>0.7</td>\n",
|
510 |
+
" <td>-0.6</td>\n",
|
511 |
+
" <td>0.8</td>\n",
|
512 |
+
" <td>1.4</td>\n",
|
513 |
+
" </tr>\n",
|
514 |
+
" <tr>\n",
|
515 |
+
" <th>3</th>\n",
|
516 |
+
" <td>394463</td>\n",
|
517 |
+
" <td>Chicago, IL</td>\n",
|
518 |
+
" <td>msa</td>\n",
|
519 |
+
" <td>3</td>\n",
|
520 |
+
" <td>IL</td>\n",
|
521 |
+
" <td>Chicago</td>\n",
|
522 |
+
" <td>Chicago, IL</td>\n",
|
523 |
+
" <td>NaN</td>\n",
|
524 |
+
" <td>2023-12-31</td>\n",
|
525 |
+
" <td>0.1</td>\n",
|
526 |
+
" <td>0.4</td>\n",
|
527 |
+
" <td>1.6</td>\n",
|
528 |
+
" <td>-0.8</td>\n",
|
529 |
+
" <td>-0.2</td>\n",
|
530 |
+
" <td>1.4</td>\n",
|
531 |
+
" </tr>\n",
|
532 |
+
" <tr>\n",
|
533 |
+
" <th>4</th>\n",
|
534 |
+
" <td>394514</td>\n",
|
535 |
+
" <td>Dallas, TX</td>\n",
|
536 |
+
" <td>msa</td>\n",
|
537 |
+
" <td>4</td>\n",
|
538 |
+
" <td>TX</td>\n",
|
539 |
+
" <td>Dallas</td>\n",
|
540 |
+
" <td>Dallas, TX</td>\n",
|
541 |
+
" <td>NaN</td>\n",
|
542 |
+
" <td>2023-12-31</td>\n",
|
543 |
+
" <td>-0.1</td>\n",
|
544 |
+
" <td>0.0</td>\n",
|
545 |
+
" <td>3.2</td>\n",
|
546 |
+
" <td>-0.6</td>\n",
|
547 |
+
" <td>0.9</td>\n",
|
548 |
+
" <td>3.6</td>\n",
|
549 |
+
" </tr>\n",
|
550 |
+
" <tr>\n",
|
551 |
+
" <th>...</th>\n",
|
552 |
+
" <td>...</td>\n",
|
553 |
+
" <td>...</td>\n",
|
554 |
+
" <td>...</td>\n",
|
555 |
+
" <td>...</td>\n",
|
556 |
+
" <td>...</td>\n",
|
557 |
+
" <td>...</td>\n",
|
558 |
+
" <td>...</td>\n",
|
559 |
+
" <td>...</td>\n",
|
560 |
+
" <td>...</td>\n",
|
561 |
+
" <td>...</td>\n",
|
562 |
+
" <td>...</td>\n",
|
563 |
+
" <td>...</td>\n",
|
564 |
+
" <td>...</td>\n",
|
565 |
+
" <td>...</td>\n",
|
566 |
+
" <td>...</td>\n",
|
567 |
+
" </tr>\n",
|
568 |
+
" <tr>\n",
|
569 |
+
" <th>20162</th>\n",
|
570 |
+
" <td>82097</td>\n",
|
571 |
+
" <td>55087</td>\n",
|
572 |
+
" <td>zip</td>\n",
|
573 |
+
" <td>39992</td>\n",
|
574 |
+
" <td>MN</td>\n",
|
575 |
+
" <td>Warsaw</td>\n",
|
576 |
+
" <td>Faribault-Northfield, MN</td>\n",
|
577 |
+
" <td>Rice County</td>\n",
|
578 |
+
" <td>2023-12-31</td>\n",
|
579 |
+
" <td>0.1</td>\n",
|
580 |
+
" <td>0.7</td>\n",
|
581 |
+
" <td>1.8</td>\n",
|
582 |
+
" <td>-0.9</td>\n",
|
583 |
+
" <td>-0.2</td>\n",
|
584 |
+
" <td>2.6</td>\n",
|
585 |
+
" </tr>\n",
|
586 |
+
" <tr>\n",
|
587 |
+
" <th>20163</th>\n",
|
588 |
+
" <td>85325</td>\n",
|
589 |
+
" <td>62093</td>\n",
|
590 |
+
" <td>zip</td>\n",
|
591 |
+
" <td>39992</td>\n",
|
592 |
+
" <td>IL</td>\n",
|
593 |
+
" <td>NaN</td>\n",
|
594 |
+
" <td>St. Louis, MO-IL</td>\n",
|
595 |
+
" <td>Macoupin County</td>\n",
|
596 |
+
" <td>2023-12-31</td>\n",
|
597 |
+
" <td>0.9</td>\n",
|
598 |
+
" <td>0.4</td>\n",
|
599 |
+
" <td>3.7</td>\n",
|
600 |
+
" <td>-0.7</td>\n",
|
601 |
+
" <td>0.4</td>\n",
|
602 |
+
" <td>2.3</td>\n",
|
603 |
+
" </tr>\n",
|
604 |
+
" <tr>\n",
|
605 |
+
" <th>20164</th>\n",
|
606 |
+
" <td>92085</td>\n",
|
607 |
+
" <td>77661</td>\n",
|
608 |
+
" <td>zip</td>\n",
|
609 |
+
" <td>39992</td>\n",
|
610 |
+
" <td>TX</td>\n",
|
611 |
+
" <td>NaN</td>\n",
|
612 |
+
" <td>Houston-The Woodlands-Sugar Land, TX</td>\n",
|
613 |
+
" <td>Chambers County</td>\n",
|
614 |
+
" <td>2023-12-31</td>\n",
|
615 |
+
" <td>-0.5</td>\n",
|
616 |
+
" <td>0.3</td>\n",
|
617 |
+
" <td>-0.6</td>\n",
|
618 |
+
" <td>-0.4</td>\n",
|
619 |
+
" <td>0.0</td>\n",
|
620 |
+
" <td>1.2</td>\n",
|
621 |
+
" </tr>\n",
|
622 |
+
" <tr>\n",
|
623 |
+
" <th>20165</th>\n",
|
624 |
+
" <td>92811</td>\n",
|
625 |
+
" <td>79078</td>\n",
|
626 |
+
" <td>zip</td>\n",
|
627 |
+
" <td>39992</td>\n",
|
628 |
+
" <td>TX</td>\n",
|
629 |
+
" <td>NaN</td>\n",
|
630 |
+
" <td>Borger, TX</td>\n",
|
631 |
+
" <td>Hutchinson County</td>\n",
|
632 |
+
" <td>2023-12-31</td>\n",
|
633 |
+
" <td>-1.2</td>\n",
|
634 |
+
" <td>-1.1</td>\n",
|
635 |
+
" <td>-3.1</td>\n",
|
636 |
+
" <td>-1.7</td>\n",
|
637 |
+
" <td>-2.6</td>\n",
|
638 |
+
" <td>-1.9</td>\n",
|
639 |
+
" </tr>\n",
|
640 |
+
" <tr>\n",
|
641 |
+
" <th>20166</th>\n",
|
642 |
+
" <td>98183</td>\n",
|
643 |
+
" <td>95419</td>\n",
|
644 |
+
" <td>zip</td>\n",
|
645 |
+
" <td>39992</td>\n",
|
646 |
+
" <td>CA</td>\n",
|
647 |
+
" <td>Camp Meeker</td>\n",
|
648 |
+
" <td>Santa Rosa-Petaluma, CA</td>\n",
|
649 |
+
" <td>Sonoma County</td>\n",
|
650 |
+
" <td>2023-12-31</td>\n",
|
651 |
+
" <td>-0.5</td>\n",
|
652 |
+
" <td>-0.2</td>\n",
|
653 |
+
" <td>0.0</td>\n",
|
654 |
+
" <td>-0.5</td>\n",
|
655 |
+
" <td>0.6</td>\n",
|
656 |
+
" <td>-0.4</td>\n",
|
657 |
+
" </tr>\n",
|
658 |
+
" </tbody>\n",
|
659 |
+
"</table>\n",
|
660 |
+
"<p>21062 rows × 15 columns</p>\n",
|
661 |
+
"</div>"
|
662 |
+
],
|
663 |
+
"text/plain": [
|
664 |
+
" RegionID RegionName RegionType SizeRank State City \\\n",
|
665 |
+
"0 102001 United States country 0 NaN NaN \n",
|
666 |
+
"1 394913 New York, NY msa 1 NY New York \n",
|
667 |
+
"2 753899 Los Angeles, CA msa 2 CA Los Angeles \n",
|
668 |
+
"3 394463 Chicago, IL msa 3 IL Chicago \n",
|
669 |
+
"4 394514 Dallas, TX msa 4 TX Dallas \n",
|
670 |
+
"... ... ... ... ... ... ... \n",
|
671 |
+
"20162 82097 55087 zip 39992 MN Warsaw \n",
|
672 |
+
"20163 85325 62093 zip 39992 IL NaN \n",
|
673 |
+
"20164 92085 77661 zip 39992 TX NaN \n",
|
674 |
+
"20165 92811 79078 zip 39992 TX NaN \n",
|
675 |
+
"20166 98183 95419 zip 39992 CA Camp Meeker \n",
|
676 |
+
"\n",
|
677 |
+
" Metro CountyName BaseDate \\\n",
|
678 |
+
"0 NaN NaN 2023-12-31 \n",
|
679 |
+
"1 New York, NY NaN 2023-12-31 \n",
|
680 |
+
"2 Los Angeles, CA NaN 2023-12-31 \n",
|
681 |
+
"3 Chicago, IL NaN 2023-12-31 \n",
|
682 |
+
"4 Dallas, TX NaN 2023-12-31 \n",
|
683 |
+
"... ... ... ... \n",
|
684 |
+
"20162 Faribault-Northfield, MN Rice County 2023-12-31 \n",
|
685 |
+
"20163 St. Louis, MO-IL Macoupin County 2023-12-31 \n",
|
686 |
+
"20164 Houston-The Woodlands-Sugar Land, TX Chambers County 2023-12-31 \n",
|
687 |
+
"20165 Borger, TX Hutchinson County 2023-12-31 \n",
|
688 |
+
"20166 Santa Rosa-Petaluma, CA Sonoma County 2023-12-31 \n",
|
689 |
+
"\n",
|
690 |
+
" Month Over Month % (Smoothed) Quarter Over Quarter % (Smoothed) \\\n",
|
691 |
+
"0 0.1 0.4 \n",
|
692 |
+
"1 0.2 0.2 \n",
|
693 |
+
"2 -0.1 -1.8 \n",
|
694 |
+
"3 0.1 0.4 \n",
|
695 |
+
"4 -0.1 0.0 \n",
|
696 |
+
"... ... ... \n",
|
697 |
+
"20162 0.1 0.7 \n",
|
698 |
+
"20163 0.9 0.4 \n",
|
699 |
+
"20164 -0.5 0.3 \n",
|
700 |
+
"20165 -1.2 -1.1 \n",
|
701 |
+
"20166 -0.5 -0.2 \n",
|
702 |
+
"\n",
|
703 |
+
" Year Over Year % (Smoothed) Month Over Month % (Raw) \\\n",
|
704 |
+
"0 3.5 -0.5 \n",
|
705 |
+
"1 1.0 -0.7 \n",
|
706 |
+
"2 0.7 -0.6 \n",
|
707 |
+
"3 1.6 -0.8 \n",
|
708 |
+
"4 3.2 -0.6 \n",
|
709 |
+
"... ... ... \n",
|
710 |
+
"20162 1.8 -0.9 \n",
|
711 |
+
"20163 3.7 -0.7 \n",
|
712 |
+
"20164 -0.6 -0.4 \n",
|
713 |
+
"20165 -3.1 -1.7 \n",
|
714 |
+
"20166 0.0 -0.5 \n",
|
715 |
+
"\n",
|
716 |
+
" Quarter Over Quarter % (Raw) Year Over Year % (Raw) \n",
|
717 |
+
"0 0.4 3.7 \n",
|
718 |
+
"1 -0.9 0.6 \n",
|
719 |
+
"2 0.8 1.4 \n",
|
720 |
+
"3 -0.2 1.4 \n",
|
721 |
+
"4 0.9 3.6 \n",
|
722 |
+
"... ... ... \n",
|
723 |
+
"20162 -0.2 2.6 \n",
|
724 |
+
"20163 0.4 2.3 \n",
|
725 |
+
"20164 0.0 1.2 \n",
|
726 |
+
"20165 -2.6 -1.9 \n",
|
727 |
+
"20166 0.6 -0.4 \n",
|
728 |
+
"\n",
|
729 |
+
"[21062 rows x 15 columns]"
|
730 |
+
]
|
731 |
+
},
|
732 |
+
"execution_count": 34,
|
733 |
+
"metadata": {},
|
734 |
+
"output_type": "execute_result"
|
735 |
+
}
|
736 |
+
],
|
737 |
+
"source": [
|
738 |
+
"cols = list(combined_df.columns)\n",
|
739 |
+
"result_cols = [x for x in cols if '%' in x]\n",
|
740 |
+
"cols\n",
|
741 |
+
"# check if string contains string\n",
|
742 |
+
"combined_df.columns\n",
|
743 |
+
"\n",
|
744 |
+
"all_cols = ['RegionID', 'RegionName', 'RegionType', 'SizeRank', 'StateName', 'State', 'City', 'Metro', 'CountyName',\n",
|
745 |
+
" 'BaseDate'] + result_cols\n",
|
746 |
+
"all_cols\n",
|
747 |
+
"\n",
|
748 |
+
"if not os.path.exists(FULL_PROCESSED_DIR_PATH):\n",
|
749 |
+
" os.makedirs(FULL_PROCESSED_DIR_PATH)\n",
|
750 |
+
"\n",
|
751 |
+
"final_df = combined_df[all_cols]\n",
|
752 |
+
"final_df = final_df.drop('StateName', axis=1)\n",
|
753 |
+
"\n",
|
754 |
+
"# iterate over rows of final_df and populate State and City columns if the regionType is msa\n",
|
755 |
+
"for index, row in final_df.iterrows():\n",
|
756 |
+
" if row['RegionType'] == 'msa':\n",
|
757 |
+
" regionName = row['RegionName']\n",
|
758 |
+
" final_df.at[index, 'Metro'] = regionName\n",
|
759 |
+
" \n",
|
760 |
+
" city = regionName.split(', ')[0]\n",
|
761 |
+
" final_df.at[index, 'City'] = city\n",
|
762 |
+
" \n",
|
763 |
+
" state = regionName.split(', ')[1]\n",
|
764 |
+
" final_df.at[index, 'State'] = state\n",
|
765 |
+
"\n",
|
766 |
+
"final_df"
|
767 |
+
]
|
768 |
+
},
|
769 |
+
{
|
770 |
+
"cell_type": "code",
|
771 |
+
"execution_count": 36,
|
772 |
+
"metadata": {},
|
773 |
+
"outputs": [],
|
774 |
+
"source": [
|
775 |
+
"final_df.to_csv(FULL_PROCESSED_DIR_PATH + 'final.csv', index=False)"
|
776 |
+
]
|
777 |
+
}
|
778 |
+
],
|
779 |
+
"metadata": {
|
780 |
+
"kernelspec": {
|
781 |
+
"display_name": "Python 3",
|
782 |
+
"language": "python",
|
783 |
+
"name": "python3"
|
784 |
+
},
|
785 |
+
"language_info": {
|
786 |
+
"codemirror_mode": {
|
787 |
+
"name": "ipython",
|
788 |
+
"version": 3
|
789 |
+
},
|
790 |
+
"file_extension": ".py",
|
791 |
+
"mimetype": "text/x-python",
|
792 |
+
"name": "python",
|
793 |
+
"nbconvert_exporter": "python",
|
794 |
+
"pygments_lexer": "ipython3",
|
795 |
+
"version": "3.12.2"
|
796 |
+
}
|
797 |
+
},
|
798 |
+
"nbformat": 4,
|
799 |
+
"nbformat_minor": 2
|
800 |
+
}
|
processed/home_value_forecasts/final.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|