From f61af79b3539d1c60df32fbd45a12a530686a5f6 Mon Sep 17 00:00:00 2001 From: "shenjian@fangjia.com" Date: Tue, 10 Jan 2023 16:47:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dags/business/business/community/price.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/dags/business/business/community/price.py b/dags/business/business/community/price.py index 1f26af6..e148e92 100644 --- a/dags/business/business/community/price.py +++ b/dags/business/business/community/price.py @@ -59,16 +59,17 @@ def sync_by_city(city, total_seaweed_df): # 小区均价 avg_price_df = commutils.get_avg_price(city=city) - avg_price_df = avg_price_df[['city', 'district_name', 'region', 'avg_price']] - avg_price_df = avg_price_df.rename(columns={'district_name': 'name'}) - seaweed_df = pd.merge(seaweed_df, avg_price_df, how='left', on=['city', 'region', 'name']) + if len(avg_price_df) > 0: + avg_price_df = avg_price_df[['city', 'district_name', 'region', 'avg_price']] + avg_price_df = avg_price_df.rename(columns={'district_name': 'name'}) + seaweed_df = pd.merge(seaweed_df, avg_price_df, how='left', on=['city', 'region', 'name']) - # 小区均价区域排名 - seaweed_df['avg_price_region_ranking'] = \ - seaweed_df.groupby(by=['city', 'region']).rank(method='first', na_option='bottom', ascending=False)['avg_price'] - # 小区均价城市排名 - seaweed_df['avg_price_ranking'] = \ - seaweed_df.groupby(by=['city']).rank(method='first', na_option='bottom', ascending=False)['avg_price'] + # 小区均价区域排名 + seaweed_df['avg_price_region_ranking'] = \ + seaweed_df.groupby(by=['city', 'region']).rank(method='first', na_option='bottom', ascending=False)['avg_price'] + # 小区均价城市排名 + seaweed_df['avg_price_ranking'] = \ + seaweed_df.groupby(by=['city']).rank(method='first', na_option='bottom', ascending=False)['avg_price'] # 12个月均价涨跌幅 avg_price_up_and_downs_df = commutils.get_avg_price_up_and_downs(cities=[city], months=-12)