优化价格类型
This commit is contained in:
@@ -27,7 +27,7 @@ def calc(city, year_month):
|
||||
office_cleaned = office[np.abs(office['Z_Score']) < 0.1]
|
||||
# 至少样本数大于等于10
|
||||
if len(office_cleaned['day_avg_price']) >= 10:
|
||||
city_price = round(office_cleaned['day_avg_price'].median(), 0)
|
||||
city_price = int(office_cleaned['day_avg_price'].median())
|
||||
region_median_count_prices = office_cleaned.groupby(office_cleaned['region'])['day_avg_price'].agg(['median', 'count']).to_dict()
|
||||
else:
|
||||
city_price = None
|
||||
@@ -52,7 +52,7 @@ def calc(city, year_month):
|
||||
|
||||
# 写入MONGODB
|
||||
action = UpdateOne({'city': city, 'cat': 'city', 'date': year_month},
|
||||
{'$set': {'city': city, 'cat': 'city', 'date': year_month, 'avg_price': city_price,
|
||||
{'$set': {'city': city, 'cat': 'city', 'date': year_month, 'avg_price': int(city_price),
|
||||
'updated_date': datetime.now()}},
|
||||
upsert=True)
|
||||
|
||||
@@ -74,19 +74,20 @@ def calc(city, year_month):
|
||||
|
||||
action = UpdateOne({'city': city, 'cat': 'district', 'date': year_month, 'district': region},
|
||||
{'$set': {'city': city, 'cat': 'district', 'date': year_month, 'district': region,
|
||||
'avg_price': round(avg_price, 0), 'updated_date': datetime.now()}},
|
||||
'avg_price': int(avg_price), 'updated_date': datetime.now()}},
|
||||
upsert=True)
|
||||
actions.append(action)
|
||||
office_sell_stat_conn.bulk_write(actions)
|
||||
log.info(f"{city} {year_month} 均价计算完毕!")
|
||||
|
||||
|
||||
yearmonth = sys.argv[1] if len(sys.argv) > 1 else ''
|
||||
|
||||
if yearmonth == '':
|
||||
date = dateutils.add_months(datetime.today(), months=-1)
|
||||
yearmonth = int(dateutils.format_date(date, '%Y%m'))
|
||||
try:
|
||||
if type(yearmonth) is str:
|
||||
yearmonth = int(yearmonth)
|
||||
for city in areautils.get_all_cities():
|
||||
calc(city, yearmonth)
|
||||
except Exception as e:
|
||||
@@ -94,7 +95,7 @@ except Exception as e:
|
||||
|
||||
# # 初始化从2024年9月
|
||||
# 创建从2024年9月到2024年12月的日期范围
|
||||
# date_range = pd.date_range(start='2024-09-01', end='2025-01-31', freq='M')
|
||||
# date_range = pd.date_range(start='2024-06-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