| | |
| | |
| |
|
| | |
| |
|
| |
|
| | import pandas as pd |
| | import os |
| |
|
| | from helpers import get_data_path_for_config, get_combined_df, save_final_df_as_jsonl |
| |
|
| |
|
| | |
| |
|
| |
|
| | CONFIG_NAME = "home_values_forecasts" |
| |
|
| |
|
| | |
| |
|
| |
|
| | data_frames = [] |
| |
|
| | data_dir_path = get_data_path_for_config(CONFIG_NAME) |
| |
|
| | for filename in os.listdir(data_dir_path): |
| | if filename.endswith(".csv"): |
| | print("processing " + filename) |
| | cur_df = pd.read_csv(os.path.join(data_dir_path, filename)) |
| |
|
| | cols = ["Month Over Month %", "Quarter Over Quarter %", "Year Over Year %"] |
| | if filename.endswith("sm_sa_month.csv"): |
| | |
| | cur_df.columns = list(cur_df.columns[:-3]) + [ |
| | x + " (Smoothed) (Seasonally Adjusted)" for x in cols |
| | ] |
| | else: |
| | |
| | cur_df.columns = list(cur_df.columns[:-3]) + cols |
| |
|
| | cur_df["RegionName"] = cur_df["RegionName"].astype(str) |
| |
|
| | data_frames.append(cur_df) |
| |
|
| |
|
| | combined_df = get_combined_df( |
| | data_frames, |
| | [ |
| | "RegionID", |
| | "RegionType", |
| | "SizeRank", |
| | "StateName", |
| | "BaseDate", |
| | ], |
| | ) |
| |
|
| | combined_df |
| |
|
| |
|
| | |
| |
|
| |
|
| | |
| | final_df = combined_df |
| | final_df = combined_df.drop("StateName", axis=1) |
| | final_df = final_df.rename( |
| | columns={ |
| | "CountyName": "County", |
| | "BaseDate": "Date", |
| | "RegionName": "Region", |
| | "RegionType": "Region Type", |
| | "RegionID": "Region ID", |
| | "SizeRank": "Size Rank", |
| | } |
| | ) |
| |
|
| | |
| | for index, row in final_df.iterrows(): |
| | if row["Region Type"] == "msa": |
| | regionName = row["Region"] |
| | |
| |
|
| | city = regionName.split(", ")[0] |
| | final_df.at[index, "City"] = city |
| |
|
| | state = regionName.split(", ")[1] |
| | final_df.at[index, "State"] = state |
| |
|
| | final_df["Date"] = pd.to_datetime(final_df["Date"], format="%Y-%m-%d") |
| |
|
| | final_df |
| |
|
| |
|
| | |
| |
|
| |
|
| | save_final_df_as_jsonl(CONFIG_NAME, final_df) |
| |
|
| |
|