mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
setting up ha24 matching
This commit is contained in:
parent
c7972fc88d
commit
975a9fa9a0
1 changed files with 51 additions and 0 deletions
|
|
@ -54,6 +54,21 @@ def load_data():
|
||||||
np.where(asset_list["row_colour_name"] == "green", "identified potential eco", "maybe in the future")
|
np.where(asset_list["row_colour_name"] == "green", "identified potential eco", "maybe in the future")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# The third column is listed as "Address" but it's actually the postcode". We have two Address columns so we
|
||||||
|
# change just the third
|
||||||
|
asset_list.columns.values[2] = "Postcode"
|
||||||
|
|
||||||
|
# Split up the address on commas, which is useful for matching later
|
||||||
|
split_addresses = asset_list['Address'].str.split(',', expand=True)
|
||||||
|
split_addresses.columns = ['temp', 'address2', 'address3', 'address4', 'address5', 'address6']
|
||||||
|
|
||||||
|
asset_list = pd.concat([asset_list, split_addresses], axis=1)
|
||||||
|
# There is no commas separating house number and address 1
|
||||||
|
split_addresses2 = asset_list['temp'].str.split(' ', expand=True)
|
||||||
|
split_addresses2.columns = ['HouseNo', 'part1', 'part2', "part3", "part4"]
|
||||||
|
# We could re-concatenate but we only care about HouseNo for the moment
|
||||||
|
asset_list = pd.concat([asset_list, split_addresses2[["HouseNo"]]], axis=1)
|
||||||
|
|
||||||
# Read in surveys
|
# Read in surveys
|
||||||
survey_workbook = openpyxl.load_workbook(f'etl/eligibility/ha_15_32/HESTIA - HA 24 ECO4 SURVEY LIST.xlsx')
|
survey_workbook = openpyxl.load_workbook(f'etl/eligibility/ha_15_32/HESTIA - HA 24 ECO4 SURVEY LIST.xlsx')
|
||||||
survey_sheet = survey_workbook.active
|
survey_sheet = survey_workbook.active
|
||||||
|
|
@ -69,5 +84,41 @@ def load_data():
|
||||||
survey_colors.append(row_color)
|
survey_colors.append(row_color)
|
||||||
|
|
||||||
survey_list = pd.DataFrame(survey_rows, columns=[cell.value for cell in survey_sheet[1]])
|
survey_list = pd.DataFrame(survey_rows, columns=[cell.value for cell in survey_sheet[1]])
|
||||||
|
|
||||||
|
survey_list["row_colour"] = survey_colors
|
||||||
|
survey_list["survey_key"] = ["survey_" + str(i) for i in range(0, len(survey_list))]
|
||||||
|
# Tidy up the street/block name a bit
|
||||||
|
survey_list["Street / Block Name"] = survey_list["Street / Block Name"].str.replace("/", ", ")
|
||||||
|
survey_list["Street / Block Name"] = survey_list["Street / Block Name"].str.lower()
|
||||||
|
|
||||||
# Drop all None rows
|
# Drop all None rows
|
||||||
survey_list = survey_list.dropna(how='all')
|
survey_list = survey_list.dropna(how='all')
|
||||||
|
survey_list["survey_key"] = ["survey_" + str(i) for i in range(0, len(survey_list))]
|
||||||
|
|
||||||
|
matched = []
|
||||||
|
for _, row in tqdm(survey_list.iterrows(), total=len(survey_list)):
|
||||||
|
house_number = row["NO."]
|
||||||
|
if isinstance(house_number, str):
|
||||||
|
house_number = house_number.lower()
|
||||||
|
|
||||||
|
# Filter on the first line of the address
|
||||||
|
df = asset_list[asset_list["Address"].str.lower().str.contains(row["Street / Block Name"].lower())].copy()
|
||||||
|
# df = df[df["Postcode"].str.lower().str.contains(row["Post Code"].lower())]
|
||||||
|
df = df[df["Address"].str.lower().str.contains(str(house_number))]
|
||||||
|
if df.shape[0] != 1:
|
||||||
|
df = df[df["HouseNo"] == str(house_number)]
|
||||||
|
if df.shape[0] != 1:
|
||||||
|
df = df[df["Postcode"].str.lower().str.contains(row["Post Code"].lower())]
|
||||||
|
if df.shape[0] != 1:
|
||||||
|
raise ValueError("Investigate")
|
||||||
|
|
||||||
|
matched.append(
|
||||||
|
{
|
||||||
|
"survey_key": row["survey_key"],
|
||||||
|
"matched_address": df["Address"].values[0],
|
||||||
|
"survey_house_no": row["NO."],
|
||||||
|
"survey_street_name": row["Street / Block Name"],
|
||||||
|
"survey_postcode": row["Post Code"],
|
||||||
|
"survey_status": row["INSTALLED OR CANCELLED"]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue