From f4f5c86e1ef1e85387fba4e934180a4ffe107514 Mon Sep 17 00:00:00 2001 From: "shenjian@fangjia.com" Date: Tue, 25 Apr 2023 14:52:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=90=8C=E6=AD=A5=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dags/business/business/community/percentile.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/dags/business/business/community/percentile.py b/dags/business/business/community/percentile.py index 8ada251..108b331 100644 --- a/dags/business/business/community/percentile.py +++ b/dags/business/business/community/percentile.py @@ -59,17 +59,21 @@ def calc_percentile(city=None): for city_now in cities: df = consumption_aim_df[consumption_aim_df['city'] == city_now].copy() - for i in range(1, 100): - df.loc[df['avg_price'] > percents_df[(percents_df['type'] == 'avg_price') & (percents_df['percent'] == i)].iloc[0]['price'], - df['avg_price'] <= percents_df[(percents_df['type'] == 'avg_price') & (percents_df['percent'] == i + 1)].iloc[0]['price'], 'avg_price_percentile'] = 101 - i + df['total_price'] /= 10000 + for i in range(1, 101): + if i == 1: + df.loc[(df['avg_price'] <= percents_df[(percents_df['type'] == 'avg_price') & (percents_df['percent'] == i)].iloc[0]['price']), 'avg_price_percentile'] = 101 - i - df.loc[df['total_price'] > percents_df[(percents_df['type'] == 'total_price') & (percents_df['percent'] == i)].iloc[0]['price'], - df['total_price'] <= percents_df[(percents_df['type'] == 'total_price') & (percents_df['percent'] == i + 1)].iloc[0]['price'], 'total_price_percentile'] = 101 - i + df.loc[(df['total_price'] <= percents_df[(percents_df['type'] == 'total_price') & (percents_df['percent'] == i)].iloc[0]['price']), 'total_price_percentile'] = 101 - i + else: + df.loc[(df['avg_price'] > percents_df[(percents_df['type'] == 'avg_price') & (percents_df['percent'] == i - 1)].iloc[0]['price']) & (df['avg_price'] <= percents_df[(percents_df['type'] == 'avg_price') & (percents_df['percent'] == i)].iloc[0]['price']), 'avg_price_percentile'] = 101 - i + + df.loc[(df['total_price'] > percents_df[(percents_df['type'] == 'total_price') & (percents_df['percent'] == i - 1)].iloc[0]['price']) & (df['total_price'] <= percents_df[(percents_df['type'] == 'total_price') & (percents_df['percent'] == i)].iloc[0]['price']), 'total_price_percentile'] = 101 - i # 批量更新 for index, item in df.iterrows(): row = dict() - _id = str(item["_id"]) + _id = str(item["id"]) row['total_price_percentile'] = item['total_price_percentile'] row['avg_price_percentile'] = item['avg_price_percentile']