Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -219,14 +219,13 @@ def load_comms(city):
|
||||
seaweed = seaweed.reset_index()
|
||||
for field in ['age', "cubage_percent", "virescence_percent", "estate_charge"]:
|
||||
seaweed[field] = seaweed[field].apply(lambda x: str2number(x))
|
||||
na_num = len(seaweed[seaweed[field].isna()])
|
||||
len(seaweed[seaweed[field].isna()])
|
||||
seaweed = fill_missing_by_around(seaweed, field)
|
||||
seaweed[field] = seaweed[field].fillna(seaweed[field].mean())
|
||||
seaweed['age'] = seaweed['age'].apply(lambda x: int(x))
|
||||
seaweed['cubage_percent'] = seaweed['cubage_percent'].apply(lambda x: round(x, 2))
|
||||
seaweed['virescence_percent'] = seaweed['virescence_percent'].apply(lambda x: round(x, 2))
|
||||
seaweed['estate_charge'] = seaweed['estate_charge'].apply(lambda x: round(x, 2))
|
||||
seaweed['age'] = seaweed['age'].astype(int)
|
||||
return seaweed
|
||||
|
||||
|
||||
@@ -346,6 +345,8 @@ def comms_rating(data):
|
||||
data[number_field] = data[number_field].apply(lambda x: threshold_95 if x >= threshold_95 else x)
|
||||
data[number_field] = data[number_field].apply(lambda x: threshold_5 if x <= threshold_5 else x)
|
||||
data[f'{number_field}_score'] = normalize_to_01(data[number_field])
|
||||
data['age'] = data['age'].apply(lambda x: int(x) if pd.notna(x) else x)
|
||||
data['age'] = data['age'].astype(int)
|
||||
for category_field in ['estate_type']:
|
||||
category_score(data, category_field, estate_type_source_map)
|
||||
data['total_score'] = 0
|
||||
@@ -515,14 +516,19 @@ def process_city(city):
|
||||
df_simple[f'block{key}_rank'] = None
|
||||
df_simple[f'block{key}_total_rank'] = None
|
||||
if df_simple['block'].notna().any():
|
||||
subset = df_simple[df_simple['block'].notna()]
|
||||
df_simple.loc[subset.index, f'block{key}_rank'] = subset.groupby(
|
||||
['city', 'region', 'block'])[factor_score_field].rank(method='dense', ascending=False).astype(int)
|
||||
df_simple.loc[subset.index, f'block{key}_total_rank'] = df_simple.loc[subset.index][f'block{key}_rank'].max()
|
||||
|
||||
for score_factor in ['total_score', 'community_quality_score', 'community_price_score',
|
||||
'location_advantage_score', 'flowability_score', 'living_facilities_score',
|
||||
'education_score', 'hospital_score']:
|
||||
buffer = []
|
||||
data_null = data[data['block'].isna()].copy()
|
||||
data_not_null = data[data['block'].notna()].copy()
|
||||
buffer.append(data_null)
|
||||
if len(data_not_null) > 0:
|
||||
data_not_null['region_block'] = data_not_null['region'] + "_" + data_not_null['block']
|
||||
for item in data_not_null['region_block'].unique():
|
||||
group = data_not_null[(data_not_null['region'] == str(item).split("_")[0])&(data_not_null['block'] == str(item).split("_")[1])].copy()
|
||||
group[f'block{key}_rank'] = group.groupby(['city', 'region', 'block'])[factor_score_field].rank(method='min', ascending=False).astype(int)
|
||||
group[f'block{key}_total_rank'] = group[f'block{key}_rank'].max()
|
||||
buffer.append(group)
|
||||
df_simple = pd.concat(buffer)
|
||||
for score_factor in ['total_score', 'community_quality_score', 'community_price_score','location_advantage_score', 'flowability_score', 'living_facilities_score','education_score', 'hospital_score']:
|
||||
df_simple[score_factor] = df_simple[score_factor].apply(lambda x: round(x, 2))
|
||||
|
||||
df_simple['rent_ro_price_ratio'] = df_simple['rent_ro_price_ratio'].apply(lambda x: round(x, 2))
|
||||
|
||||
Reference in New Issue
Block a user