-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_presale.py
84 lines (56 loc) · 1.67 KB
/
main_presale.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#%%
from RETR.collect_rawdata import load_pickle
from RETR.col_clean import *
from RETR.data_filter import *
from pathlib import Path
import matplotlib as mpl
# import matplotlib.pyplot as plt
# import pickle
# import os
#from presale_fun import *
"""
1. 各區交易量(城市, 城市2)
2. 各區總價(平均, 分位)
3. 各區成交總額 (城市, 城市2)
4. 各區單價(平均,分位) (城市, 城市2)
"""
#讀取部分
load_loc = 'D:\\check'
keyid = 1 # presale
# 儲存部分
save_file =0
xls_name = '預售屋0'
save_loc2 = 'D:\\check'
House_data = load_pickle(load_loc, key_id=1)
df0 = House_data.copy()
time_freq='Q' ; time_id = '交易-' +time_freq
df0 = time_range(df0, start=(2021,7,1), end=(2024,4,1))
df0['城市2'] = df0['城市'].apply(combine_region)
df0 = add_timef(df0, tfreq= time_freq)
#
city_group = '城市2'
transaction = compute_transaction(df0, group_col= [time_id, city_group]).unstack(city_group)
transaction['全國'] = transaction.sum(axis=1)
city_arrange = set_city_order(transaction.columns)
transaction = transaction[city_arrange]
# Price summary
# 25, 50, 75
"""
總價
"""
df0['總價萬元'] = df0['總價元'].apply(lambda x : x/10000)
ptype ='總價萬元'
quant_group = [0.25, 0.50, 0.75]
Price_summary = summarize_price(df0, ptype, time_id,city_group,quant_group, count_mean=1)
"""
每坪單價
"""
# 計算每坪單價
df1 = compute_area_p(df0)
state = '共刪除{a}筆'.format(a = df0.shape[0]-df1.shape[0])
print(state)
Unit_price = summarize_price(df1, '每坪單價(萬)', time_id, city_group, quant_group,count_mean=1 ).round(2)
"""
計算銷售總額
"""
TV = compute_total_value(df0,'總價元', time_id, city_group)