成都二手房市场分析
数据爬取自某市场份额较大的中介,基本上能代表整个成都二手房交易状况。
数据概览&整理
数据主要由2张表格构成: houseDetail.csv, 已成交房屋详细信息(18万条+)和 blockDetail.csv, 已成交房屋小区详细信息(7千条+)。
先看下数据长啥样。
df = pd.read_csv('houseDetail.csv', index_col='houseID', dtype={'houseID':str,'listedDays':str,'listedPrice':str, 'listedTime':str})
print(df.shape)
df.head(1)
(185950, 34)
agent | agentID | area | blockID | browses | buildingStructure | buildingType | builtYear | dealHouseTxt | dealedTime | decoration | district | elevator_units | feature | floor | follows | hasElevator | listedDays | listedPrice | listedTime | orientation | ownership | priceAjustment | pricePerMetre | propertyYear | title | totalPrice | transactionType | transactionYear | unitStructure | unitType | unitUsage | usableArea | visits | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
houseID | ||||||||||||||||||||||||||||||||||
106101478810 | 史于竹 | 1000000023028484 | 34.64㎡ | 1611047665350 | 603 | 钢结构 | 板塔结合 | 2008 | NaN | 2018.09.28 | 其他 | shawanhuizhan | 四梯八十五户 | 锦西国际是一个住宅小区 水电气三通民用 需要有购房资质才能购买 此小区1栋1单元4梯67户 ... | 高楼层(共22层) | 7 | 有 | 50 | 71.5 | 2018-08-10 | 南 | 暂无数据 | 1 | 20641 | 70年 | 锦西国际 | 71.5 | 商品房 | 暂无数据 | 跃层 | 2室1厅1厨1卫 | 普通住宅 | 暂无数据 | 0 |
blockDetail_df = pd.read_csv('blockDetail.csv', index_col='blockID', dtype={'blockID':str})
print(blockDetail_df.shape)
blockDetail_df.head(3)
(7222, 10)
PMC | address | buildingTypes | buildingsNum | builtYear | coordinate | developer | fee | title | unitsNum | |
---|---|---|---|---|---|---|---|---|---|---|
blockID | ||||||||||
1611047665350 | 四川博鑫物业管理有限公司 | (金牛沙湾)圃园北路1号 | 塔楼/塔板结合 | 1栋 | 2008年建成 | 104.06200416,30.70025532 | 四川名人房地产开发有限责任公司 | 1.8元/平米/月 | 锦西国际 | 1788户 |
1611061495762 | 单位自管物业 | (金牛沙湾)沙湾路71号 | 板楼 | 4栋 | 1998年建成 | 104.058682,30.699298 | 无开发商 | 0.5元/平米/月 | 沙湾路71号 | 175户 |
3011055272967 | 成都世纪城物业管理有限公司 | (金牛沙湾)金沙路169号 | 塔楼 | 7栋 | 2014年建成 | 104.053015,30.697927 | 成都国际会议展览中心 | 2至6元/平米/月 | 现代城 | 2433户 |
houseDetail 一共有185950行, 34列。blockDetail一共7222行,10列。数据类型基本都是字符串,需要做一些整理。
# 将面积转成float型。其他字段类似的作相应处理
def areaClean(df):
area = df.area
if area=='' or area=='暂无数据':
return -1
else:
return float(area[0:-1])
df['area'] = df.apply(areaClean, axis=1)
df['dealedTime'] = pd.to_datetime(df.dealedTime)
df.sort_values(by=['dealedTime', 'listedTime'], inplace=True)
数据分析
1.字段概览
- 房屋建筑面积
print('area\n', df.area.describe())
area
count 185950.000000
mean 92.011252
std 39.212880
min 8.000000
25% 67.250000
50% 87.000000
75% 111.660000
max 877.530000
最大的有800多平。
- 挂牌价
print('listedPrice\n', df.listedPrice.describe())
listedPrice
count 185950.000000
mean 85.652573
std 76.763219
min -1.000000
25% 42.000000
50% 77.000000
75% 117.000000
max 2750.000000
挂牌价均值85万,最高的是2750万
- 电梯
print('hasElvevator\n', df.hasElevator.value_counts())
hasElvevator
1 143898
0 34859
-1 7193
77%都是电梯房。
- 房屋距上次交易满了几年
print('transactionYear\n', df.transactionYear.value_counts())
transactionYear
-1 148967
5 18607
2 18376
满了5年/2年的各占约10%,其他的未知。
- 户型结构
print('unitStructure\n', df.unitStructure.value_counts())
unitStructure
-1 132101
平层 50938
跃层 1699
错层 749
复式 462
Loft 1
- 房屋属性
print('unitUsage\n', df.unitUsage.value_counts())
unitUsage
普通住宅 178530
商业办公类 3778
车库 2781
别墅 858
商业 1
写字楼 1
四合院 1
成交最多的当然是住宅。后面就重点分析住宅的情况。
2. 成交量
- 按房屋建成年代统计成交量
tmp = df.builtYear.value_counts().sort_index(ascending=False)
x = tmp.index.tolist()[:-1]
y = tmp.values.tolist()[:-1]
plt.figure(figsize=(13, 8), facecolor='w')
plt.bar(x,y)
plt.grid()
plt.title('Number of builtYear')
plt.show()
成交得最多的是08-13年建成的房子。
- 挂牌当天就成交的数量
tmp = df[df.listedDays ==1]
print('挂牌当天就成交的数量::', tmp.shape[0])
plt.figure(figsize=(13, 8), facecolor='w')
tmp.groupby('dealedTime').c