Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -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"})
|
seaweed = seaweed.rename(columns={"create_year": "build_year", "estate_type2": "estate_type", "business_quarter": "block", "_id": "comm_id"})
|
||||||
year = datetime.now().year
|
year = datetime.now().year
|
||||||
seaweed['build_year'] = seaweed['build_year'].apply(lambda x: extract_years(x))
|
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['age'] = seaweed['build_year'].apply(lambda x: (year - x) if pd.notna(x) else None)
|
||||||
seaweed = seaweed.reset_index()
|
seaweed = seaweed.reset_index()
|
||||||
for field in ['age', "cubage_percent", "virescence_percent", "estate_charge"]:
|
for field in ['age', "cubage_percent", "virescence_percent", "estate_charge"]:
|
||||||
seaweed[field] = seaweed[field].apply(lambda x: str2number(x))
|
seaweed[field] = seaweed[field].apply(lambda x: str2number(x))
|
||||||
|
seaweed[f"org_{field}"] = seaweed[field]
|
||||||
seaweed = fill_missing_by_around(seaweed, field)
|
seaweed = fill_missing_by_around(seaweed, field)
|
||||||
seaweed[field] = seaweed[field].fillna(seaweed[field].mean())
|
seaweed[field] = seaweed[field].fillna(seaweed[field].mean())
|
||||||
seaweed['age'] = seaweed['age'].apply(lambda x: int(x))
|
if field == 'age':
|
||||||
seaweed['cubage_percent'] = seaweed['cubage_percent'].apply(lambda x: round(x, 2))
|
seaweed['age'] = seaweed['age'].apply(lambda x: int(x))
|
||||||
seaweed['virescence_percent'] = seaweed['virescence_percent'].apply(lambda x: round(x, 2))
|
else:
|
||||||
seaweed['estate_charge'] = seaweed['estate_charge'].apply(lambda x: round(x, 2))
|
seaweed[field] = seaweed[field].apply(lambda x: round(x, 2))
|
||||||
return seaweed
|
return seaweed
|
||||||
|
|
||||||
|
|
||||||
@@ -232,6 +234,7 @@ def load_comm_stat(city):
|
|||||||
{"city": 1, "region": 1, "district_name": 1, "avg_price_2b": 1,
|
{"city": 1, "region": 1, "district_name": 1, "avg_price_2b": 1,
|
||||||
"_id": 0})))
|
"_id": 0})))
|
||||||
stat = stat.rename(columns={"district_name": "name", "avg_price_2b": "avg_price"})
|
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(
|
one_year_before_stat = pd.DataFrame(list(
|
||||||
stat_client.find({"weekend": dateutils.add_months(dateutils.get_last_weekend(), days=-52 * 7), "city": city},
|
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})))
|
{"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"})
|
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 = 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['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['yoy'] = stat['yoy'].fillna(stat['yoy'].mean())
|
||||||
stat['resistance_coef'] = normalize_to_01(stat['yoy']) * 95
|
stat['resistance_coef'] = normalize_to_01(stat['yoy']) * 95
|
||||||
stat['resistance_coef'] = stat['resistance_coef'] + 2
|
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"})
|
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 = stat.merge(sqmetre_rent, on=['city', 'region', 'name'], how='left')
|
||||||
stat['rent_to_price_ratio'] = stat['sqmetre_rent'] * 12 / stat['avg_price'] * 100
|
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())
|
stat['rent_to_price_ratio'] = stat['rent_to_price_ratio'].fillna(stat['rent_to_price_ratio'].mean())
|
||||||
return stat
|
return stat
|
||||||
|
|
||||||
@@ -278,6 +284,7 @@ def load_comms_summary(city):
|
|||||||
for key in source.keys():
|
for key in source.keys():
|
||||||
if key.endswith("num") or key.endswith("_distance"):
|
if key.endswith("num") or key.endswith("_distance"):
|
||||||
community_summary[key] = source[key]
|
community_summary[key] = source[key]
|
||||||
|
community_summary[f"org_{key}"] = source[key]
|
||||||
all_community_summary.append(community_summary)
|
all_community_summary.append(community_summary)
|
||||||
all_community_summary = pd.DataFrame(all_community_summary)
|
all_community_summary = pd.DataFrame(all_community_summary)
|
||||||
return 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",
|
"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",
|
"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"]
|
"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()
|
df_simple = data[db_fields].copy()
|
||||||
if "block" not in df_simple.columns:
|
if "block" not in df_simple.columns:
|
||||||
df_simple['block'] = None
|
df_simple['block'] = None
|
||||||
|
|||||||
Reference in New Issue
Block a user