北上广深租房信息分析
北上广深租房信息分析
分析目的
根据链家网北上广深四个城市的所有租房数据(时间节点:2019年2月25日),数据共有105258条。
分析不同地区,租房的高低主要与哪些因素有关
不同的因素导致的房价差异大概是多少
数据读取
# 导入模块
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import metrics
%matplotlib inline
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
df=pd.read_csv(r'D:\BI study download\北上广深租房\data_sample.csv')
df.head()
空值查询
df.isnull().sum()
这些空值对数据影响不大,因此不用处理
数据清洗
# 删除不需要的列
df= df.drop(columns='_id')
df = df.drop(columns='rent_price_unit')
# rent_area字段有些填写的是一个范围,比如23-25平房米,后期转换成“float”类型的时候不好转换,考虑取平均值
def get_aver(data):if isinstance(data, str) and '-' in data:low, high = data.split('-')return (int(low)+int(high))/2else:return int(data)
df['rent_area'] = df['rent_area'].apply(get_aver)
# 价格是有区间的,需要按照处理rent_area一样的方法处理
df['rent_price_listing'] = df['rent_price_listing'].apply(get_aver)
df.info()
价格描述
df.rent_price_listing.hist(bins=50)
大部分价格处于300-15000之间,因此删除价格大于15000的数据,使其接近正态分布。
df=df[df['rent_price_listing']<=15000]
数据分析与可视化
各城市房源数量分布
def get_city_zf_loc(city, city_short, col=['longitude', 'latitude', 'dist'], data=df):file_name = 'data_' + city_short + '_latlon.csv'data_latlon = data.loc[data['city']==city, col].dropna(subset=['latitude', 'longitude'])data_latlon['longitude'] = data_latlon['longitude'].astype(str)data_latlon['latitude'] = data_latlon['latitude'].astype(str)data_latlon['latlon'] = data_latlon['longitude'].str.cat(data_latlon['latitude'], sep=',')data_latlon.to_csv(file_name, index=False)print(city+'的数据一共有{}条'.format(data_latlon.shape[0]))get_city_zf_loc('北京', 'bj', ['longitude','latitude', 'dist'])
get_city_zf_loc('上海', 'sh', ['longitude','latitude', 'dist'])
get_city_zf_loc('广州', 'gz', ['longitude','latitude', 'dist'])
get_city_zf_loc('深圳', 'sz', ['longitude','latitude', 'dist'])
北京的数据一共有2652条
上海的数据一共有2559条
广州的数据一共有2945条
深圳的数据一共有2764条
#北京房源数量
fig = plt.figure(dpi=300)
df.dropna(subset=['latitude', 'longitude'])[df['city']=='北京']['dist'].value_counts(ascending=True).plot.barh()
#上海房源分布
fig = plt.figure(dpi=300)
df.dropna(subset=['latitude', 'longitude'])[df['city']=='上海']['dist'].value_counts(ascending=True).plot.barh()
fig = plt.figure(dpi=300)
df.dropna(subset=['latitude', 'longitude'])[df['city']=='广州']['dist'].value_counts(ascending=True).plot.barh()
fig = plt.figure(dpi=300)
df.dropna(subset=['latitude', 'longitude'])[df['city']=='深圳']['dist'].value_counts(ascending=True).plot.barh()
总结:
北京的房源大部分都在朝阳区,其他区的房源数量不到朝阳区的一般
上海的房源大部分在浦东,和北京分布类似
广州和深圳的房源分布比价均衡,各区之间差异不太大
各城市房价分布
rent_city=df.groupby(['city']).rent_price_listing.mean().sort_values()
rent_city.plot.barh(figsize=[6,7], color=['#2f83e4','#00e5c1','#23cbff'],)
plt.title('各城市的平均房价对比')
fig = plt.figure(dpi=300)
df.dropna(subset=['latitude', 'longitude'])[df['city']=='北京'].groupby(['dist'])['rent_price_listing'].mean().sort_values(ascending=True).plot.barh()
fig = plt.figure(dpi=300)
df.dropna(subset=['latitude', 'longitude'])[df['city']=='上海'].groupby(['dist'])['rent_price_listing'].mean().sort_values(ascending=True).plot.barh()
fig = plt.figure(dpi=300)
df.dropna(subset=['latitude', 'longitude'])[df['city']=='广州'].groupby(['dist'])['rent_price_listing'].mean().sort_values(ascending=True).plot.barh()
fig = plt.figure(dpi=300)
df.dropna(subset=['latitude', 'longitude'])[df['city']=='深圳'].groupby(['dist'])['rent_price_listing'].mean().sort_values(ascending=True).plot.barh()
总结:
从城市总体来看,房租数量高低分别是北京、上海、深圳、广州
北京房租最高的四个区是海淀、东城、朝阳、西城,达到了8000元
上海市房租最高的区是静安、黄埔、长宁,达到了9000,其中静安最高达到了10000
广州的房价普遍不高,最高的越秀区刚过5000
深圳的南山、罗湖和福田房租最高,在6000元左右
可以看出房租和城市以及区位置的关系非常密切
面积对房租的影响
#对房间面积进行分组
def area_func(x):if 0<=x<20:return('0~20')elif 20<=x<50:return('20~50')elif 50<=x<75:return('50~75')elif 75<=x<100:return('75~100')elif 100<=x<200:return('100~200')elif 20<=x:return('200~')
rent_gp_ra = df[df['city']=='北京'].groupby('rent_area').rent_price_listing.mean()
rent_gp_ra = rent_gp_ra.reset_index()
rent_gp_ra['rent_area']=rent_gp_ra.rent_area.apply(area_func)
rent_gp_ra_2 = rent_gp_ra.groupby('rent_area').rent_price_listing.mean()
rent_gp_ra_2 = rent_gp_ra_2.sort_values()
rent_gp_ra_2.plot.barh(figsize=[6,7], color=['#2f83e4','#00e5c1','#23cbff'],)
plt.title('北京不同房间面积的房租均价')
for x,y in enumerate(rent_gp_ra_2):plt.text(y,x,'%s' %round(y,1),ha='center')
其他区的代码同上
随着面积的不断增大,价格也逐渐增高。
200平以上,价格高低依次是:北京、深圳、广州、上海
100-200平,价格高低依次是:北京、上海、深圳、广州
75-100平,价格高低依次是: 深圳、北京、上海、广州
50-175平,价格高低依次是:北京、深圳、上海、广州
20-50平,价格高低依次是: 北京、上海、深圳、广州
0-20平,价格高低依次是:上海、北京、深圳、广州
上海的小面积房屋要普遍更贵,广州的价格比较低,性价比更高些,毕业生的压力会更小些。
房屋类型对价格的影响
rent_la = df[df['city']=='北京'].groupby('layout').rent_price_listing.mean().sort_values().head(10)
rent_la.plot.barh(figsize=[6,2.5], color=['#2f83e4','#00e5c1'],)
plt.title('不同房间类型的房租')
除了上海,其他三个地区房价最低的房型都属于合租房,且价格均在2000以下
上海基本都是整租,因此房价比较高。
地铁对房价的影响
from scipy import stats
def distance_price_relation(city, data=df):g = sns.jointplot(x="distance", y="rent_price_listing", data=df[(df['city']==city)&(df['rent_price_listing'])].dropna(subset=['distance']), kind="reg",stat_func=stats.pearsonr)g.fig.set_dpi(100)g.ax_joint.set_xlabel('最近地铁距离', fontweight='bold')g.ax_joint.set_ylabel('租金', fontweight='bold')return g
distance_price_relation('北京')
distance_price_relation('上海')
distance_price_relation('广州')
distance_price_relation('深圳')
普遍来说离地铁越远价格越低,但差别并不明显,因此推荐离地铁近的房子。
总结
- 在所有影响房屋的价格因素中,位置和面积对房租的影响最大。
- 除了合租外,其他的房型对价格的影响也不大
- 地铁的距离对房租的影响很小,因此有条件的话建议选择离地铁近的房子。
北上广深租房信息分析相关推荐
- 用Python分析北上广深租房情况,租房时优先考虑哪些因素?
俗话说"金三银四",又到了换工作.乃至换城市的时候了.这对于"回望楼价又一年"的小伙伴们来说,也意味着又到了搬家换房子的时候了.北上广深四个一线城市,哪个城市的 ...
- 爬取了10W条数据,我们整理出了这份北上广深租房图鉴
戳蓝字"CSDN云计算"关注我们哦! 作者:AlfredWu 转自: Alfred数据室 俗话说"金三银四",又到了春招换工作.乃至换城市的时候了.这对于&qu ...
- 数据残酷物语:北上广深租房图鉴
俗话说"金三银四",又到了春招换工作.乃至换城市的时候了.这对于"回望楼价又一年"的小伙伴们来说,也意味着又到了搬家换房子的时候了.北上广深四个一线城市,哪个城 ...
- python空气质量分析报告_Python数据可视化:2018年北上广深空气质量分析
原标题:Python数据可视化:2018年北上广深空气质量分析 作者:法纳斯特,Python爱好者,专注爬虫,数据分析及可视化 就在这周偶然看到一个学弟吐槽天津的空气,不禁想起那段厚德载雾,自强不吸的 ...
- 疫情后北上广深租房价格跌了吗? | Alfred数据室
去年3月份我们发布了<北上广深租房图鉴>(点击阅读),细数了北上广深租房的各种因素对租房价格的影响.一年过去了,在面临新冠疫情的后续影响.城市尚未完全恢复正常运转.学校还没开学等情况下,北 ...
- Python数据可视化:2018年北上广深空气质量分析
感谢关注天善智能,走好数据之路↑↑↑ 欢迎关注天善智能,我们是专注于商业智能BI,人工智能AI,大数据分析与挖掘领域的垂直社区,学习,问答.求职一站式搞定! 对商业智能BI.大数据分析挖掘.机器学习, ...
- Python数据可视化:2018年北上广深空气质量分析(附完整代码)
♚ 法纳斯特,Python爱好者,喜欢爬虫,数据分析以及可视化. 就在这周偶然看到一个学弟吐槽天津的空气,不禁想起那段厚德载雾,自强不吸的日子. 无图无真相,下图为证. 左边的图是去年2月份的时候,这 ...
- 利用python + pyecharts+Pandas对北上广深等城市进行租房数据分析
本次分析的租房数据主要来源于上一篇博客中获取的"房天下"网站租房信息,对该数据分析主要使用了Pandas数据处理库. 利用python pyecharts进行租房情况数据分析 数据 ...
- 北上广深自如合租房图鉴
1.合租房源基本情况 我们爬取了自如北上广深合计4.58万租房信息,其中合租房3.37万,占比75%. 自如在其大本营北京房源最多,达到了1.62万间,其次是上海为1.14万间.相比之下,其在广深的房 ...
最新文章
- Oracle Study之--Oracle等待事件(3)
- 什么是shell,shell基础由浅入深,常用的shell命令、用法、技巧
- hdu 5167 bfs
- ar9344 9382 8035 编程器固件_沈阳熔铜炉设计,紧固件加热炉_宏祥电炉
- 1、SpringBoot------表单校验
- caffe在ubuntu18.04下编译
- [新思路]Online DVD Rental! 美国在线DVD租赁
- AMP、HMP、SMP
- 1、Redhat GNOME安装访问命令行
- Thrift搭建分布式微服务(四)
- python day - 19 抽象类 接口类 多态 封装
- 乔布斯声称Google先决定当苹果的敌人
- 咋做数据分析,张口就来RFM模型,结果用错了
- 基于Java+Springboot+mybatis+lyaui的学科竞赛管理系统设计和实现
- ArcMap进行地图标注与注记
- 卷积神经网路之感受野(receptive field)的理解
- vmbox挂载共享目录
- 据说,2021年Apple将推出1416英寸MacBook Pro
- 输入两个整数,求;两者的和,差,积,商,余数。
- “隐私面单”让个人信息不再“裸奔”
热门文章
- 5月挑战Day19-Online Stock Span(Medium)
- jquery事件代理方法
- 【蜂口 | AI人工智能】人脸颜值——龙鹏 深度学习与人脸图像应用连载(五)...
- 深度了解什么是结构体对齐
- com.ashokvarma.android:bottom-navigation 修改导航栏图片和文字间的距离和文字的大小
- Node-RED学习(一)
- html获得文本框的值,jQuery中怎么获取文本框的值?
- Django使用JavaScript弹出确认删除提示框
- 开挂的00后!17岁「天才少女」被8所世界名校录取,最终选择MIT计算机系
- php连接mysql 1045_连接mysql报1045错误怎么办