From 084992265e6d9b7ad1480d0af0a60f4bc1d0b135 Mon Sep 17 00:00:00 2001 From: "shenjian@fangjia.com" Date: Tue, 29 Nov 2022 10:46:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=89=A9=E4=B8=9A=E8=B4=B9?= =?UTF-8?q?=E8=AF=84=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/estate_charge_ranking.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/dags/business/business/community/estate_charge_ranking.py b/dags/business/business/community/estate_charge_ranking.py index c75475a..84eb3ef 100644 --- a/dags/business/business/community/estate_charge_ranking.py +++ b/dags/business/business/community/estate_charge_ranking.py @@ -7,6 +7,7 @@ import logging import os from elasticsearch import helpers import matplotlib.pyplot as plt +import numpy as np from sklearn.mixture import GaussianMixture @@ -47,13 +48,17 @@ def filter_min_max(city, community_summary_df): """ 过滤极值 """ - if city in factor_dict: - community_summary_df.loc[ - community_summary_df['estate_charge'] < factor_dict[city]['min_estate_charge'], 'estate_charge'] = \ - factor_dict[city]['min_estate_charge'] - community_summary_df.loc[ - community_summary_df['estate_charge'] > factor_dict[city]['max_estate_charge'], 'estate_charge'] = \ - factor_dict[city]['max_estate_charge'] + estate_charge5 = np.percentile(a=community_summary_df['estate_charge'], q=2, axis=0) + estate_charge95 = np.percentile(a=community_summary_df['estate_charge'], q=98, axis=0) + community_summary_df.loc[community_summary_df['estate_charge'] > estate_charge95, 'estate_charge'] = estate_charge95 + community_summary_df.loc[community_summary_df['estate_charge'] < estate_charge5, 'estate_charge'] = estate_charge5 + # if city in factor_dict: + # community_summary_df.loc[ + # community_summary_df['estate_charge'] < factor_dict[city]['min_estate_charge'], 'estate_charge'] = \ + # factor_dict[city]['min_estate_charge'] + # community_summary_df.loc[ + # community_summary_df['estate_charge'] > factor_dict[city]['max_estate_charge'], 'estate_charge'] = \ + # factor_dict[city]['max_estate_charge'] return community_summary_df @@ -105,6 +110,7 @@ def sync_by_city(city_now): if 'estate_charge' not in columns: log.warning(f"{city_now}无法评级,缺少因子") return + community_summary_df = community_summary_df.dropna(how='any').copy() community_summary_df = filter_min_max(city_now, community_summary_df).copy() community_summary_df = calc_estate_charge_rating(community_summary_df) if len(community_summary_df) == 0: