handling case of missing built form

This commit is contained in:
Khalim Conn-Kowlessar 2023-12-22 16:17:53 +00:00
parent 29599c5154
commit 612922df6a
3 changed files with 29 additions and 22 deletions

View file

@ -40,7 +40,7 @@ def standardise_ha_4(data):
data["Location Name"] = data["Location Name"].str.strip() data["Location Name"] = data["Location Name"].str.strip()
# Remove any unusable postcodes # Remove any unusable postcodes
data = data[data["Post Code"] != '\\\\'] data = data[data["Post Code"] != '\\\\'].copy()
# Some specific replacements # Some specific replacements
data["Location Name"] = np.where( data["Location Name"] = np.where(
@ -75,7 +75,8 @@ def get_ha_4_data(data, cleaned, cleaning_data, created_at):
searcher.search() searcher.search()
if searcher.data is None: if searcher.data is None:
vlsh nodata.append(property_meta.to_dict())
continue
epcs = searcher.data["rows"] epcs = searcher.data["rows"]
epcs = pd.DataFrame(epcs) epcs = pd.DataFrame(epcs)
@ -117,25 +118,27 @@ def get_ha_4_data(data, cleaned, cleaning_data, created_at):
) )
scoring_data.extend(scoring_dictionary) scoring_data.extend(scoring_dictionary)
results.append( results.append(
{ {
"row_id": property_meta["row_id"], "row_id": property_meta["row_id"],
"gbis_eligible": eligibility.gbis_warmfront, "Location Name": property_meta["Location Name"],
"eco4_eligible": eligibility.eco4_warmfront["eligible"], "Post Code": property_meta["Post Code"],
"eco4_message": eligibility.eco4_warmfront["message"], "gbis_eligible": eligibility.gbis_warmfront,
"sap": float(eligibility.epc["current-energy-efficiency"]), "eco4_eligible": eligibility.eco4_warmfront["eligible"],
"gbis_eligible_future": eligibility.gbis["eligible"], "eco4_message": eligibility.eco4_warmfront["message"],
"gbis_eligible_future_message": eligibility.gbis["message"], "sap": float(eligibility.epc["current-energy-efficiency"]),
"eco4_eligible_future": eligibility.eco4["eligible"], "gbis_eligible_future": eligibility.gbis["eligible"],
"eco4_eligible_future_message": eligibility.eco4["message"], "gbis_eligible_future_message": eligibility.gbis["message"],
# Property components "eco4_eligible_future": eligibility.eco4["eligible"],
"roof": eligibility.roof["clean_description"], "eco4_eligible_future_message": eligibility.eco4["message"],
"walls": eligibility.walls["clean_description"], # Property components
"heating": eligibility.epc["mainheat-description"], "roof": eligibility.roof["clean_description"],
"tenure": eligibility.tenure, "walls": eligibility.walls["clean_description"],
"date_epc": eligibility.epc["lodgement-date"], "heating": eligibility.epc["mainheat-description"],
} "tenure": eligibility.tenure,
) "date_epc": eligibility.epc["lodgement-date"],
}
)
def app(): def app():

View file

@ -492,12 +492,16 @@ class DataProcessor:
how='left' how='left'
) )
global_averages = cleaning_data[cols_to_clean].mean()
# Fill NaN values with averages # Fill NaN values with averages
for col in cols_to_clean: for col in cols_to_clean:
data_to_clean[col].fillna(data_to_clean[f"{col}_AVERAGE"], inplace=True) data_to_clean[col].fillna(data_to_clean[f"{col}_AVERAGE"], inplace=True)
data_to_clean.drop(columns=[f"{col}_AVERAGE"], inplace=True) data_to_clean.drop(columns=[f"{col}_AVERAGE"], inplace=True)
# If we still have missings # If we still have missings
data_to_clean[col].fillna(data_to_clean[col].mean(), inplace=True) data_to_clean[col].fillna(data_to_clean[col].mean(), inplace=True)
# Final step if we still have missings - use global mean
data_to_clean[col].fillna(global_averages[col], inplace=True)
return data_to_clean return data_to_clean

View file

@ -548,7 +548,7 @@ def estimate_external_wall_area(num_floors, floor_height, perimeter, built_form)
'Detached': 4, 'Detached': 4,
} }
exposed_wall_area = total_wall_area * (number_exposed_walls[built_form] / 4) exposed_wall_area = total_wall_area * (number_exposed_walls.get(built_form, 3) / 4)
return exposed_wall_area return exposed_wall_area