修复区域价格NAN问题
This commit is contained in:
+14
-13
@@ -26,7 +26,7 @@ def calc(city, year_month):
|
|||||||
# 剔除Z-score超过0.1的异常值
|
# 剔除Z-score超过0.1的异常值
|
||||||
office_cleaned = office[np.abs(office['Z_Score']) < 0.1]
|
office_cleaned = office[np.abs(office['Z_Score']) < 0.1]
|
||||||
city_price = round(office_cleaned['day_avg_price'].mean(), 2)
|
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:
|
else:
|
||||||
city_price = None
|
city_price = None
|
||||||
region_avg_prices = {}
|
region_avg_prices = {}
|
||||||
@@ -52,17 +52,18 @@ def calc(city, year_month):
|
|||||||
upsert=True)
|
upsert=True)
|
||||||
|
|
||||||
actions.append(action)
|
actions.append(action)
|
||||||
for region, avg_price in region_avg_prices.items():
|
for region in areautils.get_all_districts(city):
|
||||||
# 不会出现NaN的情况, 因为聚合来的
|
if region in region_avg_prices:
|
||||||
#if pd.isna(avg_price):
|
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):
|
district_stat = office_rent_stat_conn.find_one({'city': city, 'cat': 'district', 'date': last_month, 'district': region})
|
||||||
# continue
|
if pd.isna(district_stat):
|
||||||
# last_month_region_price = district_stat['avg_price']
|
continue
|
||||||
# if pd.isna(last_month_region_price):
|
last_month_region_price = district_stat['avg_price']
|
||||||
# continue
|
if pd.isna(last_month_region_price):
|
||||||
# avg_price = last_month_region_price
|
continue
|
||||||
|
avg_price = last_month_region_price
|
||||||
|
|
||||||
action = UpdateOne({'city': city, 'cat': 'district', 'date': year_month, 'district': region},
|
action = UpdateOne({'city': city, 'cat': 'district', 'date': year_month, 'district': region},
|
||||||
{'$set': {'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)
|
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')
|
# date_range = pd.date_range(start='2023-01-01', end='2024-12-31', freq='M')
|
||||||
#
|
#
|
||||||
# # 创建一个包含这些日期的DataFrame
|
# # 创建一个包含这些日期的DataFrame
|
||||||
|
|||||||
Reference in New Issue
Block a user