zillow / processors /days_on_market.py
misikoff's picture
fix:update
69c22e0
raw
history blame
No virus
2.13 kB
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
import os
from helpers import (
get_combined_df,
save_final_df_as_jsonl,
handle_slug_column_mappings,
)
# In[2]:
DATA_DIR = "../data"
PROCESSED_DIR = "../processed/"
FACET_DIR = "days_on_market/"
FULL_DATA_DIR_PATH = os.path.join(DATA_DIR, FACET_DIR)
FULL_PROCESSED_DIR_PATH = os.path.join(PROCESSED_DIR, FACET_DIR)
# In[3]:
data_frames = []
exclude_columns = [
"RegionID",
"SizeRank",
"RegionName",
"RegionType",
"StateName",
"Home Type",
]
slug_column_mappings = {
"_mean_listings_price_cut_amt_": "Mean Listings Price Cut Amount",
"_med_doz_pending_": "Median Days on Pending",
"_median_days_to_pending_": "Median Days to Close",
"_perc_listings_price_cut_": "Percent Listings Price Cut",
}
for filename in os.listdir(FULL_DATA_DIR_PATH):
if filename.endswith(".csv"):
print("processing " + filename)
# skip month files for now since they are redundant
if "month" in filename:
continue
cur_df = pd.read_csv(os.path.join(FULL_DATA_DIR_PATH, filename))
if "_uc_sfrcondo_" in filename:
cur_df["Home Type"] = "all homes (SFR + Condo)"
# change column type to string
cur_df["RegionName"] = cur_df["RegionName"].astype(str)
elif "_uc_sfr_" in filename:
cur_df["Home Type"] = "SFR"
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
# In[9]:
# Adjust column names
final_df = combined_df.rename(
columns={
"RegionID": "Region ID",
"SizeRank": "Size Rank",
"RegionName": "Region",
"RegionType": "Region Type",
"StateName": "State",
}
)
final_df
# In[5]:
save_final_df_as_jsonl(FULL_PROCESSED_DIR_PATH, final_df)