北上广深租房信息分析

北上广深租房信息分析

分析目的

根据链家网北上广深四个城市的所有租房数据(时间节点: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))/2
    else:
        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', 
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值