日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2023/12/15 python 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)

設置橢圓

責任編輯:

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的python找房源_Python租房信息分析!找到最适合自己的房源信息!的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。