pandas杭州市出租房分析( 三 )


info3=info2[~info2['m_room_type'].str.contains(r'.*(0卫|9卫).*')]
通过以上一系列处理最终得到3665条数据 。
数据分析及可视化
房源租赁类型分布情况
导人画图的相关包
import matplotlib.pyplot as plt #导入图像库import seaborn as snsplt.rcParams['font.sans-serif'] = ['SimHei'] #用来正常显示中文标签plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号import seaborn as sns% matplotlib inlinesns.set(context='notebook',font='simhei',style='darkgrid')info3.type.value_counts().plot(kind='pie',autopct='%3.2f %%')plt.title('租赁类型分布')plt.xlabel('租赁类型')plt.ylabel('房源数量')plt.legend()
可以发现合租房源略多于整租房源 。
房源的区域分布
ax=info3.groupby('district').type.count().sort_values(ascending=False).plot(kind='bar',figsize=(16,6))district_r=info3.groupby('district').type.count().sort_values(ascending=False).cumsum()/info3.groupby('district').type.count().sort_values(ascending=False).cumsum().max()ax2 = ax.twinx()district_r.plot()ax.set_xlabel('区域')ax.set_ylabel('房源数量')ax2.set_yticks(np.arange(0,1.1,0.1))plt.title('房源的区域分布')
杭州市现有10个行政区 , 其中70%房源主要集中在江干区,西湖区 , 拱墅区,萧山 。比较神奇的是萧山比滨江区多 , 且在前3 , 可能是由萧山已发展起来 , 又与滨江区接壤,萧山相对滨江租金便宜,因此招租的多 。
房源的户型分布情况
import redef substr_room(s):room=re.findall(r'[0-9]室',s)return room[0]info3['room']=info3.m_room_type.apply(substr_room)ax=info3.groupby('room').type.count().sort_values(ascending=False).plot(kind='bar',figsize=(16,6))room_type_r=info3.groupby('room').type.count().sort_values(ascending=False).cumsum()/info3.groupby('room').type.count().sort_values(ascending=False).cumsum().max()ax2 = ax.twinx()room_type_r.plot()ax.set_xlabel('户型')ax.set_ylabel('房源数量')ax2.set_yticks(np.arange(0,1.1,0.1))plt.title('房源的户型分布')
一半多的房型是3室 , 现在的房屋户型设计基本都是3室 , 和实际租房情况相符 。
房源的面积分布情况
#将房间面积按区间分类def area_range(an):if an<=10:area_range = '5-10平'elif an>10 and an<=20:area_range = '10-20平'elif an>20 and an<=30:area_range = '20-30平'elif an>30 and an<=40:area_range = '30-40平'elif an>40 and an<=50:area_range = '40-50平'else:area_range = '50平以上'return area_rangeinfo3['area_range']=info.m_area.apply(area_range)#画饼状图labels = info3.area_range.value_counts().indexfracs = info3.area_range.value_counts().valuesfig = plt.figure(figsize=(10,6))plt.axes(aspect=1)plt.pie(x=fracs, labels=labels, autopct='%3.2f %%',shadow=False, labeldistance=1.1, startangle=60, pctdistance=0.6)plt.show
10-20平米的房间最多 , 占总房源的41.31% , 20-30平米的占18.91% , 可选范围还是比较广的 。
总体租金分布情况
fig = plt.figure(figsize = (20,7))plt.hist(info3['price_int'], bins=15, rwidth=0.95, alpha=0.7)plt.title('总体租金分布情况')plt.xlabel('元/月')plt.ylabel('频率')plt.xticks(range(500,20000,500))