优化
This commit is contained in:
@@ -25,11 +25,16 @@ def calc(city, year_month):
|
||||
office['Z_Score'] = (office['day_avg_price'] - office['day_avg_price'].mean()) / office['day_avg_price'].std()
|
||||
# 剔除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().to_dict()
|
||||
# 至少样本数大于等于10
|
||||
if len(office_cleaned['day_avg_price']) >= 10:
|
||||
city_price = round(office_cleaned['day_avg_price'].median(), 2)
|
||||
region_median_count_prices = office_cleaned.groupby(office_cleaned['region'])['day_avg_price'].agg(['median', 'count']).to_dict()
|
||||
else:
|
||||
city_price = None
|
||||
region_median_count_prices = {'median': {}, 'count': {}}
|
||||
else:
|
||||
city_price = None
|
||||
region_avg_prices = {}
|
||||
region_median_count_prices = {'median': {}, 'count': {}}
|
||||
|
||||
actions = list()
|
||||
|
||||
@@ -53,7 +58,9 @@ def calc(city, year_month):
|
||||
|
||||
actions.append(action)
|
||||
for region in areautils.get_all_districts(city):
|
||||
if region in region_avg_prices:
|
||||
region_avg_prices = region_median_count_prices['median']
|
||||
region_count = region_median_count_prices['count']
|
||||
if region in region_avg_prices and region_count[region] >= 10:
|
||||
avg_price = region_avg_prices[region]
|
||||
else:
|
||||
# 处理均价为空情况,用上月均价替代
|
||||
@@ -85,9 +92,9 @@ try:
|
||||
except Exception as e:
|
||||
log.error(e)
|
||||
|
||||
# # 初始化跑两年
|
||||
# # 创建从2024年1月到2024年12月的日期范围
|
||||
# date_range = pd.date_range(start='2023-01-01', end='2024-12-31', freq='M')
|
||||
# # 初始化从2024年9月
|
||||
# 创建从2024年9月到2024年12月的日期范围
|
||||
# date_range = pd.date_range(start='2024-09-01', end='2025-01-31', freq='M')
|
||||
#
|
||||
# # 创建一个包含这些日期的DataFrame
|
||||
# df = pd.DataFrame({'date': date_range, 'value': range(1, len(date_range) + 1)})
|
||||
|
||||
Reference in New Issue
Block a user