python找房源_Python租房信息分析!找到最适合自己的房源信息!

原标题:Python租房信息分析!找到最适合自己的房源信息!

租房信息分析

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

import seaborn as sns

file_data = pd.read_csv("./data/链家北京租房数据.csv")

file_data

file_data.shape

file_data.head

file_data.info

file_data.describe

# 重复值

# file_data.duplicated

file_data = file_data.drop_duplicates

file_data.shape

# 空值处理

file_data = file_data.dropna

file_data.shape

删除空值,最好先做判断

空值处理

file_data = file_data.dropna

# 单个值实现

file_data["面积(㎡)"].values[0][:-2]

# 创建一个空的数组

data_new = np.array([])

data_area = file_data["面积(㎡)"].values

for i in data_area:

data_new = np.append(data_new, np.array(i[:-2]))

# 转换data_new中的数据类型

data_new = data_new.astype(np.float64)

file_data.loc[:, "面积(㎡)"] = data_new

house_data = file_data["户型"]

temp_list = []

for i in house_data:

# print(i)

new_info = i.replace("房间", "室")

temp_list.append(new_info)

file_data.loc[:, "户型"] = temp_list

房源数量、位置分布分析

file_data["区域"].unique

new_df = pd.DataFrame({"区域":file_data["区域"].unique, "数量":[0]*13})

# 获取每个区域房源数量

area_count = file_data.groupby(by="区域").count

new_df["数量"] = area_count.values

new_df.sort_values(by="数量", ascending=False)

户型数量分析

def all_house(arr):

key = np.unique(arr)

result = {}

for k in key:

mask = (arr == k)

arr_new = arr[mask]

v = arr_new.size

result[k] = v

return result

house_info = all_house(house_data)

去掉统计数量较少的值

# 去掉统计数量较少的值

house_data = dict((key, value) for key, value in house_info.items if value > 50)

show_houses = pd.DataFrame({"户型": [x for x in house_data.keys],

"数量": [x for x in house_data.values]})

图形展示

# 图形展示房屋类型

house_type = show_houses["户型"]

house_type_num = show_houses["数量"]

plt.barh(range(11), house_type_num)

plt.yticks(range(11), house_type)

plt.xlim(0, 2500)

plt.title("北京市各区域租房数量统计")

plt.xlabel("数量")

plt.ylabel("房屋类型")

# 给每个条上面添加具体数字

for x, y in enumerate(house_type_num):

# print(x, y)

plt.text(y+0.5, x-0.2, "%s" %y)

plt.show

for x, y in enumerate(house_type_num):

print(x, y)

拿到定点坐标位置,在坐标位置附上Y值

平均租金分析

df_all = pd.DataFrame({"区域": file_data["区域"].unique,

"房租总金额": [0]*13,

"总面积": [0]*13})

sum_price = file_data["价格(元/月)"].groupby(file_data["区域"]).sum

sum_area = file_data["面积(㎡)"].groupby(file_data["区域"]).sum

df_all["房租总金额"] = sum_price.values

df_all["总面积"] = sum_area.values

计算各个区域每平方米的房租

# 计算各个区域每平方米的房租

df_all["每平米租金(元)"] = round(df_all["房租总金额"] / df_all["总面积"], 2)

合并

df_merge = pd.merge(new_df, df_all)

图形可视化

# 图形可视化

num = df_merge["数量"]

price = df_merge["每平米租金(元)"]

lx = df_merge["区域"]

l = [i for i in range(13)]

fig = plt.figure(figsize=(10, 8), dpi=100)

# 显示折线图

ax1 = fig.add_subplot(111)

ax1.plot(l, price, "or-", label="价格")

for i, (_x, _y) in enumerate(zip(l, price)):

plt.text(_x+0.2, _y, price[i])

ax1.set_ylim([0, 160])

ax1.set_ylabel("价格")

plt.legend(loc="upper right")

# 显示条形图

ax2 = ax1.twinx

plt.bar(l, num, label="数量", alpha=0.2, color="green")

ax2.set_ylabel("数量")

plt.legend(loc="upper left")

plt.xticks(l, lx)

plt.show

创建x,y轴共享

增加刻度,字符串一一对应

面积基本分析

# 查看房屋的最大面积和最小面积

print('房屋最大面积是%d平米'%(file_data['面积(㎡)'].max))

print('房屋最小面积是%d平米'%(file_data['面积(㎡)'].min))

# 查看房租的最高值和最小值

print('房租最高价格为每月%d元'%(file_data['价格(元/月)'].max))

print('房屋最低价格为每月%d元'%(file_data['价格(元/月)'].min))

面积划分

# 面积划分

area_divide = [1, 30, 50, 70, 90, 120, 140, 160, 1200]

area_cut = pd.cut(list(file_data["面积(㎡)"]), area_divide)

area_cut_num = area_cut.describe

饼图展示

# 图像可视化

area_per = (area_cut_num["freqs"].values)*100

labels = ['30平米以下', '30-50平米', '50-70平米', '70-90平米',

'90-120平米','120-140平米','140-160平米','160平米以上']

plt.figure(figsize=(20, 8), dpi=100)

# plt.axes(aspect=1)

plt.pie(x=area_per, labels=labels, autopct="%.2f %%")

plt.legend

plt.show

plt.axes(aspect=1)

设置椭圆

责任编辑:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这是一个比较复杂的任务,需要使用Python的爬虫技术来实现。以下是一个基本的爬取深圳租房网站房源信息及图片的代码框架,供您参考: ```python import requests from bs4 import BeautifulSoup import os # 设置请求头,防止被网站识别为爬虫 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} # 获取网页内容 def get_html(url): try: response = requests.get(url, headers=headers) if response.status_code == 200: return response.content except requests.RequestException as e: print(e) return None # 解析网页内容,获取房源信息及图片链接 def parse_html(html): soup = BeautifulSoup(html, 'lxml') # TODO: 解析网页内容,获取房源信息及图片链接 return house_list, img_list # 下载图片到本地 def download_image(url, path): response = requests.get(url, headers=headers) if response.status_code == 200: with open(path, 'wb') as f: f.write(response.content) # 主函数,遍历每一页获取房源信息及图片链接,并下载图片到本地 def main(): # TODO: 遍历每一页获取房源信息及图片链接,并下载图片到本地 pass if __name__ == '__main__': main() ``` 在这个代码框架,我们需要先获取网页内容,然后解析网页内容,获取房源信息及图片链接。最后,我们遍历每一页获取房源信息及图片链接,并下载图片到本地。 注:由于深圳租房网站的网页结构可能会不断变化,以上代码仅供参考,具体实现需要根据网站的实际情况进行调整。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值