Merge remote-tracking branch 'origin/master'

This commit is contained in:
沈健
2025-06-20 13:10:01 +08:00
+16 -5
View File
@@ -211,16 +211,18 @@ def load_comms(city):
seaweed = seaweed.rename(columns={"create_year": "build_year", "estate_type2": "estate_type", "business_quarter": "block", "_id": "comm_id"})
year = datetime.now().year
seaweed['build_year'] = seaweed['build_year'].apply(lambda x: extract_years(x))
seaweed['org_build_year'] = seaweed['build_year']
seaweed['age'] = seaweed['build_year'].apply(lambda x: (year - x) if pd.notna(x) else None)
seaweed = seaweed.reset_index()
for field in ['age', "cubage_percent", "virescence_percent", "estate_charge"]:
seaweed[field] = seaweed[field].apply(lambda x: str2number(x))
seaweed[f"org_{field}"] = seaweed[field]
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))
if field == 'age':
seaweed['age'] = seaweed['age'].apply(lambda x: int(x))
else:
seaweed[field] = seaweed[field].apply(lambda x: round(x, 2))
return seaweed
@@ -232,6 +234,7 @@ def load_comm_stat(city):
{"city": 1, "region": 1, "district_name": 1, "avg_price_2b": 1,
"_id": 0})))
stat = stat.rename(columns={"district_name": "name", "avg_price_2b": "avg_price"})
stat['org_avg_price'] = stat["avg_price"]
one_year_before_stat = pd.DataFrame(list(
stat_client.find({"weekend": dateutils.add_months(dateutils.get_last_weekend(), days=-52 * 7), "city": city},
{"city": 1, "region": 1, "district_name": 1, "avg_price_2b": 1, "_id": 0})))
@@ -239,6 +242,7 @@ def load_comm_stat(city):
columns={"district_name": "name", "avg_price_2b": "one_year_before_avg_price"})
stat = stat.merge(one_year_before_stat, on=['city', 'region', 'name'], how="left")
stat['yoy'] = (stat['avg_price'] - stat['one_year_before_avg_price']) * 100 / stat['one_year_before_avg_price']
stat['org_yoy'] = stat["yoy"]
stat['yoy'] = stat['yoy'].fillna(stat['yoy'].mean())
stat['resistance_coef'] = normalize_to_01(stat['yoy']) * 95
stat['resistance_coef'] = stat['resistance_coef'] + 2
@@ -264,6 +268,8 @@ def load_comm_stat(city):
sqmetre_rent = sqmetre_rent.rename(columns={"district_name": "name", "avg_price": "sqmetre_rent"})
stat = stat.merge(sqmetre_rent, on=['city', 'region', 'name'], how='left')
stat['rent_to_price_ratio'] = stat['sqmetre_rent'] * 12 / stat['avg_price'] * 100
stat["org_sqmetre_rent"] = stat['sqmetre_rent']
stat["org_rent_to_price_ratio"] = stat['rent_to_price_ratio']
stat['rent_to_price_ratio'] = stat['rent_to_price_ratio'].fillna(stat['rent_to_price_ratio'].mean())
return stat
@@ -278,6 +284,7 @@ def load_comms_summary(city):
for key in source.keys():
if key.endswith("num") or key.endswith("_distance"):
community_summary[key] = source[key]
community_summary[f"org_{key}"] = source[key]
all_community_summary.append(community_summary)
all_community_summary = pd.DataFrame(all_community_summary)
return all_community_summary
@@ -489,7 +496,11 @@ def process_city(city):
"key_primary_school_num", "ordinary_primary_school_num", "key_middle_school_num",
"ordinary_middle_school_num", "top_three_hospital_num", "non_3a_hospital_num", "build_year", "age",
"cubage_percent", "virescence_percent", "estate_charge", 'estate_type', 'resistance_coef', "region_rating"]
# 恢复经过转换,填充的数据
for field in data.columns:
if field.startswith("org_"):
data[f"{field.replace('org_', '')}"] = data[field]
del data[field]
df_simple = data[db_fields].copy()
if "block" not in df_simple.columns:
df_simple['block'] = None