#安居客新房房价分析
##读取数据
import pandas as pd
import numpy as np
from pandas import DataFrame, Series
df = pd.read_csv(u'./showInfo.csv', sep=',')
##预处理数据
#去掉没有标明价格的楼盘
usefull = df[df.price != '待定']
#将数据类型转换为float;也可以在代码 中更改
usefull[['price']] = usefull[['price']].astype(float)
#去重
usefull = usefull.drop_duplicates(['name'])
##普通住宅新房数量新房数量
fzCount = usefull.groupby('region').count()[['name']]
fzCount.plot(kind='barh')
- 郑州市区数高新区的供应量比较大,其他中心城区都是10套左右
- 其他就是郑州周边的县市
##显示楼盘均价
#这个就是可以在notebook中生成图像
%matplotlib inline
avgPrice = usefull.groupby('region').price.mean()
avgPrice.plot(kind='barh',rot=0)
##求每个区的每个户型的总面积
#one ,tow ,three等表示的是房子有一室、二室等
house = usefull[['region','name','one','two','three','four','five']]
#统计每个区域的每种户型的面积总和。例如中原区所有楼盘的的一户型的面积总和
area_sums = house.groupby('region')['name','region','one','two','three','four','five'].sum()
area_sums
##求每个区的每个户型的楼盘个数
#统计每个区域每种户型的数目。例如中原区一户型共有多少个楼盘
def funcSign(test):
for key in ['one','two','three','four','five']:
test[key] = np.sign(test[key])
return test
typeCount=funcSign(house)
typeCount = typeCount.groupby('region').sum()
typeCount
##按照不同区计算每种户型的平均面积
avgAreaOftype = area_sums/typeCount
#因为typeCount有点值为0,所以除法会出现NaN,so 要填充这些值
c = c.fillna(0)
avgAreaOftype
#显示每个区不同户型的平均面积
avgAreaOftype.plot(kind='barh',stacked=True)
- 可以发现基本上没有五户型的
- 每个区都有2、3、4户型,而且面积差不多
##每个楼盘的每个户型的总价
def computes(test):
for key in ['one','two','three','four','five']:
total = key + 's'
print total
test[total] = test.price.mul(test[key])
return test
totolPrice = computes(usefull)
totolPrice
某个户型总价:按照总价在按照交通时间排序
totolPrice = totolPrice.sort_values(axis=0, by=['twos','tranTime'],ascending=False)
totolPrice[['region','name','tranTime','twos']]
##按照交通时间范围 找楼盘
###处理数据
f[['tranTime']] = f[['tranTime']].astype(int)
#下面根据交通时间(单位为s)分类;以大于一小时为far;小于半小时为close;
f['dis'] = map(lambda x: 'far' if x>=3600 else ('mid' if (x<3600 and x>=1800) else 'close' ) , f['tranTime'])
按照交通时间 统计房源数量
# axes = plt.subplots(1, 1, figsize=(10, 8))
f.groupby(['region','dis']).region.count().unstack('dis').plot(kind='bar',figsize=(9, 6))
、
- 新房中还数高新区的房子到目的地比较近