修复区域价格NAN问题
This commit is contained in:
+14
-13
@@ -26,7 +26,7 @@ def calc(city, year_month):
|
||||
# 剔除Z-score超过0.1的异常值
|
||||
office_cleaned = office[np.abs(office['Z_Score']) < 0.1]
|
||||
city_price = round(office_cleaned['day_avg_price'].mean(), 2)
|
||||
region_avg_prices = office_cleaned.groupby(office_cleaned['region'])['day_avg_price'].mean()
|
||||
region_avg_prices = office_cleaned.groupby(office_cleaned['region'])['day_avg_price'].mean().to_dict()
|
||||
else:
|
||||
city_price = None
|
||||
region_avg_prices = {}
|
||||
@@ -52,17 +52,18 @@ def calc(city, year_month):
|
||||
upsert=True)
|
||||
|
||||
actions.append(action)
|
||||
for region, avg_price in region_avg_prices.items():
|
||||
# 不会出现NaN的情况, 因为聚合来的
|
||||
#if pd.isna(avg_price):
|
||||
# # 处理均价为空情况,用上月均价替代
|
||||
# district_stat = office_rent_stat_conn.find_one({'city': city, 'cat': 'district', 'date': last_month, 'district': region})
|
||||
# if pd.isna(district_stat):
|
||||
# continue
|
||||
# last_month_region_price = district_stat['avg_price']
|
||||
# if pd.isna(last_month_region_price):
|
||||
# continue
|
||||
# avg_price = last_month_region_price
|
||||
for region in areautils.get_all_districts(city):
|
||||
if region in region_avg_prices:
|
||||
avg_price = region_avg_prices[region]
|
||||
else:
|
||||
# 处理均价为空情况,用上月均价替代
|
||||
district_stat = office_rent_stat_conn.find_one({'city': city, 'cat': 'district', 'date': last_month, 'district': region})
|
||||
if pd.isna(district_stat):
|
||||
continue
|
||||
last_month_region_price = district_stat['avg_price']
|
||||
if pd.isna(last_month_region_price):
|
||||
continue
|
||||
avg_price = last_month_region_price
|
||||
|
||||
action = UpdateOne({'city': city, 'cat': 'district', 'date': year_month, 'district': region},
|
||||
{'$set': {'city': city, 'cat': 'district', 'date': year_month, 'district': region,
|
||||
@@ -85,7 +86,7 @@ except Exception as e:
|
||||
log.error(e)
|
||||
|
||||
# # 初始化跑两年
|
||||
# # # 创建从2024年1月到2024年12月的日期范围
|
||||
# # 创建从2024年1月到2024年12月的日期范围
|
||||
# date_range = pd.date_range(start='2023-01-01', end='2024-12-31', freq='M')
|
||||
#
|
||||
# # 创建一个包含这些日期的DataFrame
|
||||
|
||||
Reference in New Issue
Block a user