|
|
|
|
|
|
|
|
|
|
|
|
|
import pandas as pd |
|
import os |
|
|
|
from helpers import ( |
|
get_data_path_for_config, |
|
get_combined_df, |
|
save_final_df_as_jsonl, |
|
handle_slug_column_mappings, |
|
set_home_type, |
|
) |
|
|
|
|
|
|
|
|
|
|
|
CONFIG_NAME = "sales" |
|
|
|
|
|
|
|
|
|
|
|
data_frames = [] |
|
|
|
exclude_columns = [ |
|
"RegionID", |
|
"SizeRank", |
|
"RegionName", |
|
"RegionType", |
|
"StateName", |
|
"Home Type", |
|
] |
|
|
|
slug_column_mappings = { |
|
"_median_sale_to_list_": "Median Sale to List Ratio", |
|
"_mean_sale_to_list_": "Mean Sale to List Ratio", |
|
"_median_sale_price_": "Median Sale Price", |
|
"_pct_sold_above_list_": "% Sold Above List", |
|
"_pct_sold_below_list_": "% Sold Below List", |
|
"_sales_count_now_": "Nowcast", |
|
} |
|
|
|
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) |
|
|
|
if "month" in filename: |
|
continue |
|
|
|
cur_df = pd.read_csv(os.path.join(data_dir_path, filename)) |
|
|
|
cur_df = set_home_type(cur_df, filename) |
|
|
|
data_frames = handle_slug_column_mappings( |
|
data_frames, slug_column_mappings, exclude_columns, filename, cur_df |
|
) |
|
|
|
|
|
combined_df = get_combined_df( |
|
data_frames, |
|
[ |
|
"RegionID", |
|
"SizeRank", |
|
"RegionName", |
|
"RegionType", |
|
"StateName", |
|
"Home Type", |
|
"Date", |
|
], |
|
) |
|
|
|
combined_df |
|
|
|
|
|
|
|
|
|
|
|
|
|
final_df = combined_df.rename( |
|
columns={ |
|
"RegionID": "Region ID", |
|
"SizeRank": "Size Rank", |
|
"RegionName": "Region", |
|
"RegionType": "Region Type", |
|
"StateName": "State", |
|
} |
|
) |
|
|
|
final_df["Date"] = pd.to_datetime(final_df["Date"]) |
|
final_df.sort_values(by=["Region ID", "Home Type", "Date"]) |
|
|
|
|
|
|
|
|
|
|
|
final_df["Date"] = pd.to_datetime(final_df["Date"], format="%Y-%m-%d") |
|
|
|
final_df |
|
|
|
|
|
|
|
|
|
|
|
save_final_df_as_jsonl(CONFIG_NAME, final_df) |
|
|
|
|