? ? ? 大家好,我是帶我去滑雪,每天教你一個(gè)小技巧!
? 1、數(shù)據(jù)展示? ?
本文利用Python爬取到的房?jī)r(jià)信息做數(shù)據(jù)可視化,爬取數(shù)據(jù)的文章見(jiàn):
(利用Python爬取房?jī)r(jià)信息(附代碼)_用python爬取房?jī)r(jià)數(shù)據(jù)_帶我去滑雪的博客-CSDN博客)
? ? ? 所爬取的指標(biāo)有小區(qū)名稱、房屋位置、房屋戶型、房屋面積、房屋朝向、房屋裝修情況、有無(wú)電梯、樓層位置、附件有無(wú)地鐵、關(guān)注度人數(shù)、看房次數(shù)、每平方米價(jià)格、房屋總價(jià)等指標(biāo),具體數(shù)據(jù)展示見(jiàn)表1,表2。
表1 python爬取數(shù)據(jù)展示(一)
編號(hào) |
標(biāo)題 |
小區(qū)名稱 |
房屋位置 |
房屋戶型 |
房屋面積(m2 ) |
房屋朝向 |
1 |
鴻城花園 精致兩房 南向高樓層 |
鴻城花園 |
市橋 |
2室2廳 |
78.6 |
西南 |
2 |
嶺南新世界 帶空中花園實(shí)用 |
嶺南新世界 |
白云大道北 |
4室2廳 |
98 |
西南 |
3 |
隆康花園 2室1廳 255萬(wàn) |
隆康花園 |
白云大道南 |
2室1廳 |
58.1 |
西南 |
4 |
南北對(duì)流 樓層好 視野寬闊 采光充足 |
荷景花園一區(qū) |
沙灣 |
4室2廳 |
118 |
東南 ?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-432947.html |
表2 python爬取數(shù)據(jù)展示(續(xù)一)
編號(hào) |
房屋裝修情況 |
有無(wú)電梯 |
樓層位置 |
附近有無(wú)地鐵 |
關(guān)注度(人數(shù)) |
看房次數(shù) |
每平方米價(jià)格(元) |
房屋總價(jià)(萬(wàn)元) |
1 |
其他 |
有電梯 |
高樓層 |
有地鐵 |
58 |
14 |
26718 |
210 |
2 |
其他 |
有電梯 |
低樓層 |
有地鐵 |
2337 |
18 |
44184 |
433 |
3 |
簡(jiǎn)裝 |
有電梯 |
中樓層 |
有地鐵 |
25 |
18 |
43890 |
255 |
4 |
精裝 |
無(wú)電梯 |
中樓層 |
無(wú)地鐵 |
2106 |
6 |
16526 |
195 |
5 |
簡(jiǎn)裝 |
無(wú)電梯 |
高樓層 |
無(wú)地鐵 |
1533 |
7 |
15354 |
150 |
6 |
簡(jiǎn)裝 |
有電梯 |
中樓層 |
有地鐵 |
47 |
5 |
49164 |
570 |
2、數(shù)據(jù)預(yù)處理
? ? ? ?數(shù)據(jù)預(yù)處理是指在數(shù)據(jù)集中發(fā)現(xiàn)不準(zhǔn)確、不完整或者不合理的數(shù)據(jù),通過(guò)數(shù)據(jù)預(yù)處理,對(duì)這些數(shù)據(jù)進(jìn)行一定的去重、修補(bǔ)、糾正或移除,將原始數(shù)據(jù)轉(zhuǎn)化成分析算法適用的形式,以此提高數(shù)據(jù)質(zhì)量。由于爬取的數(shù)據(jù)中包含類(lèi)別型數(shù)據(jù),為了方便后面數(shù)據(jù)分析,本文對(duì)分類(lèi)型數(shù)據(jù)進(jìn)行了分別賦值,處理后的變量表見(jiàn)表3,處理后的數(shù)據(jù)集部分見(jiàn)表4。
表3?變量表
屬性 |
解釋 |
類(lèi)型 |
變量名 |
WSSL |
房屋的臥室數(shù)量(個(gè)) |
連續(xù)值 |
x1 |
KTSL |
房屋的客廳數(shù)量(個(gè)) |
連續(xù)值 |
x2 |
MJ |
房屋面積(平方米) |
連續(xù)值 |
x3 |
FWZXQK |
房屋裝修情況 |
離散值,0=其他;1=毛坯;2=簡(jiǎn)裝;3=精裝 |
x4 |
YWDT |
有無(wú)電梯 |
離散值,0=無(wú)電梯;1=有電梯 |
x5 |
LCWZ |
房屋所在樓層位置 |
離散值,0=低樓層;1=中樓層;2=高樓層 |
x6 |
FJYWDT |
房屋附近有無(wú)地鐵 |
離散值,0=無(wú)地鐵;1=有地鐵 |
x7 |
GZD |
關(guān)注度(人次) |
連續(xù)值 |
x8 |
KFCS |
看房次數(shù) |
連續(xù)值 |
x9 |
PRICE |
每平方米價(jià)格(元) |
連續(xù)值 |
y |
TOTAL PRICE |
房屋總價(jià)(萬(wàn)元) |
連續(xù)值 |
y1 |
表4?經(jīng)過(guò)數(shù)據(jù)預(yù)處理后的數(shù)據(jù)集
編號(hào) |
x1 |
x2 |
x3 |
x4 |
x5 |
x6 |
x7 |
x8 |
x9 |
y |
y1 |
1 |
2 |
2 |
78.6 |
0 |
1 |
2 |
1 |
58 |
14 |
26718 |
210 |
2 |
4 |
2 |
98 |
0 |
1 |
0 |
1 |
2337 |
18 |
44184 |
433 |
3 |
2 |
1 |
58.1 |
2 |
1 |
1 |
1 |
25 |
18 |
43890 |
255 |
4 |
4 |
2 |
118 |
3 |
0 |
1 |
0 |
2106 |
6 |
16526 |
195 |
5 |
3 |
1 |
97.7 |
2 |
0 |
2 |
0 |
1533 |
7 |
15354 |
150 |
6 |
3 |
2 |
115.94 |
2 |
1 |
1 |
1 |
47 |
5 |
49164 |
570 |
7 |
3 |
2 |
102.72 |
2 |
1 |
0 |
1 |
80 |
19 |
61332 |
630 |
8 |
3 |
2 |
102.72 |
2 |
1 |
0 |
1 |
80 |
19 |
61332 |
630 |
9 |
2 |
2 |
73.3 |
2 |
1 |
0 |
1 |
873 |
21 |
42292 |
310 |
10 |
3 |
2 |
92 |
2 |
1 |
1 |
0 |
64 |
14 |
22066 |
203 |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
? |
2981 |
2 |
1 |
80.3 |
2 |
1 |
1 |
1 |
8 |
0 |
46700 |
375 |
2982 |
2 |
2 |
64.81 |
2 |
1 |
1 |
1 |
2 |
0 |
41352 |
268 |
2983 |
2 |
1 |
57.26 |
0 |
0 |
0 |
1 |
0 |
0 |
41041 |
235 |
2984 |
2 |
1 |
75.38 |
2 |
1 |
2 |
0 |
0 |
0 |
39799 |
300 |
3、數(shù)據(jù)分析
3.1 詞云分析
? ? ? ? 詞云是文本大數(shù)據(jù)可視化的一種重要方式,該方法可以將文本信息中重復(fù)出現(xiàn)的詞語(yǔ)進(jìn)行高亮展示,使瀏覽文本信息的人們可以一眼看到關(guān)鍵信息。本文利用python對(duì)表1中的標(biāo)題文本信息進(jìn)行詞云分析,輸出結(jié)果見(jiàn)圖1所示。
? ? ? ?通過(guò)圖1可以發(fā)現(xiàn),在某網(wǎng)站上所掛樓房標(biāo)題詞中最多的是中間樓層、精裝修、看房方便、采光好、近地鐵、樓層好等字樣,說(shuō)明可能具有這些特點(diǎn)的房子更能吸引買(mǎi)家的注意,進(jìn)而影響房屋的價(jià)格。
繪制詞云圖
import pandas as pd
file = open(r'\title.xlsx','rb')
data = pd.read_excel(file)
data.columns
title = data['標(biāo)題']
import numpy as np
import os
lis =? np.array(title)
lis = lis.tolist()
lis[:5]
str1 = "".join(lis)
item_main = str1.strip().replace('span','').replace('class','').replace('emoji','').replace(' ','')
def save_fig(fig_id, tight_layout=True):
??? path = os.path.join(r" E:\工作\碩士\學(xué)習(xí)\統(tǒng)計(jì)軟件python\期末作業(yè)", fig_id + ".png")
??? print("Saving figure", fig_id)
??? if tight_layout:
??????? plt.tight_layout()
??? plt.savefig(path, format='png', dpi=300)
import jieba
wordlist = jieba.cut(item_main,cut_all=True)
word_space_split =" ".join(wordlist)
type(word_space_split)
import matplotlib.pyplot as plt
from wordcloud import WordCloud,ImageColorGenerator
import PIL.Image as Image
coloring = np.array(Image.open(r'\Desktop\圖片.jpg'))
my_wordcloud = WordCloud(background_color='white',max_words=200,mask=coloring,max_font_size=60,random_state=42,
scale=2,font_path=r'C:\Windows\Fonts\simkai.ttf').generate(item_main)
image_colors = ImageColorGenerator(coloring)
plt.imshow(my_wordcloud.recolor(color_func=image_colors))
plt.imshow(my_wordcloud)
plt.axis('off')
save_fig('my_wordcloud_fangjia')
plt.show()
3.2 描述性分析
? ? ? ? 利用python對(duì)搜集到的數(shù)據(jù)進(jìn)行描述性分析,為了更加清晰的展示數(shù)據(jù),分別繪制了餅圖、條形圖、嵌套環(huán)形圖等圖形,繪制圖形的python代碼見(jiàn)附件,其結(jié)果見(jiàn)圖2、圖3、圖4、圖5、圖6所示。
?3.3 相關(guān)性分析
? ? (1)房屋面積與房屋總價(jià)
? ? (2)房屋總價(jià)與關(guān)注度人數(shù)
? ? (3)房屋臥室個(gè)數(shù)與房屋總價(jià)
?文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-432947.html
圖2房屋裝修情況占比餅狀圖
import numpy as np
import matplotlib.pyplot as plt
data = pd.read_csv(r"E:\工作\碩士\學(xué)習(xí)\統(tǒng)計(jì)軟件python\期末作業(yè)\qxhsj.csv")
plt.rcParams['font.sans-serif'] = ["Fangsong"]
plt.rcParams['axes.unicode_minus'] = False
# 設(shè)置畫(huà)布大小
plt.figure(figsize=(12,6))
figure,axes = plt.subplots(1,1,figsize = (6,6),dpi = 120)
# 構(gòu)造數(shù)據(jù)
y = [1139,33,891,921]
label=["其他", "毛坯", "簡(jiǎn)裝", "精裝"]
# 繪圖
plt.pie(y,
??????? labels=label, #
??????? autopct='%.2f%%', # 讓標(biāo)簽以百分比形式顯示,且精確到兩位小數(shù)
??????? labeldistance = 1.1,
??????? pctdistance = 0.9,
#???????? shadow = True,
??????? radius = 1,?
??????? startangle = 90,?
??????? counterclock = False?
?????? )
plt.title("房屋裝修情況占比",fontsize = 12)
plt.savefig(r"E:\工作\碩士\學(xué)習(xí)\統(tǒng)計(jì)軟件python\matplotlib餅圖.jpg", format="png")
# 可視化呈現(xiàn)
plt.show()
圖3房屋所在樓層位置比例餅狀圖
import numpy as np
import matplotlib.pyplot as plt
data = pd.read_csv(r"E:\工作\碩士\學(xué)習(xí)\統(tǒng)計(jì)軟件python\期末作業(yè)\qxhsj.csv")
plt.rcParams['font.sans-serif'] = ["Fangsong"]
plt.rcParams['axes.unicode_minus'] = False
plt.figure(figsize=(12,6))
figure,axes = plt.subplots(1,1,figsize = (6,6),dpi = 120)
y = [806,1143,1036]
label=["低樓層", "中樓層", "高樓層"]
plt.pie(y,
??????? labels=label,
??????? autopct='%.2f%%',
??????? labeldistance = 1.1,
??????? pctdistance = 0.9,
#??????? shadow = True,
??????? radius = 1,?
??????? startangle = 90,?
??????? counterclock = False?
?????? )
plt.title("房屋所在樓層位置比例",fontsize = 12)
plt.savefig(r"E:\工作\碩士\學(xué)習(xí)\統(tǒng)計(jì)軟件python\matplotlib餅圖.jpg", format="png")
plt.show()
圖4房源朝向分布情況
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.family']='KaiTi'
plt.figure(dpi=120)
provinces=['東', '南', '西', '北', '東南','東北', '西南', '西北']
gdp=[250, 1137,169, 768, 432,237,222,160]
plt.barh(provinces[::-1],gdp[::-1],height=0.5)
plt.title('房源朝向分布情況')
plt.grid(axis='x',ls='--',alpha=0.4)
plt.xlim(0,1200)
for i,j in enumerate(gdp[::-1]):
??? plt.text(j+0.05,i,j,va='center')
plt.xlabel('數(shù)量')
plt.ylabel('朝向')
plt.savefig(r"E:\工作\碩士\學(xué)習(xí)\統(tǒng)計(jì)軟件python\matplotlib條形圖.jpg",format="png")
plt.show()
圖5 房屋戶型與房屋附近有無(wú)地鐵的嵌套環(huán)形圖
import pyecharts.options as opts
from pyecharts.charts import Pie
inner_x_data = ["有地鐵", "無(wú)地鐵"]
inner_y_data = [1548, 1436]
inner_data_pair = [list(z) for z in zip(inner_x_data, inner_y_data)]
outer_x_data = [' 1室0廳 ',? '2室1廳', '2室2廳', '3室1廳' '1室1廳', '3室2廳','1室2廳', '4室1廳', '4室2廳','其他']
outer_y_data = [47,621,611,215,144,1021,12,11,224,81]
outer_data_pair = [list(z) for z in zip(outer_x_data, outer_y_data)]
(
??? Pie(init_opts=opts.InitOpts(width="1600px", height="800px"))
??? .add(
??????? series_name="有無(wú)地鐵",
??????? data_pair=inner_data_pair,
??????? radius=[0, "30%"],
??????? label_opts=opts.LabelOpts(position="inner"),
??? )
??? .add(
??????? series_name="房型",
??????? radius=["40%", "55%"],
??????? data_pair=outer_data_pair,
??????? label_opts=opts.LabelOpts(
??????????? position="outside",
??????????? formatter="{a|{a}}{abg|}\n{hr|}\n {b|: }{c}? {per|n5n3t3z%}? ",
??????????? background_color="#eee",
??????????? border_color="#aaa",
??????????? border_width=1,
??????????? border_radius=4,
??????????? rich={
??????????????? "a": {"color": "#999", "lineHeight": 22, "align": "center"},
??????????????? "abg": {
???? ???????????????"backgroundColor": "#e3e3e3",
??????????????????? "width": "100%",
??????????????????? "align": "right",
??????????????????? "height": 22,
??????????????????? "borderRadius": [4, 4, 0, 0],
??????????????? },
??????????????? "hr": {
???????? ???????????"borderColor": "#aaa",
??????????????????? "width": "100%",
??????????????????? "borderWidth": 0.5,
??????????????????? "height": 0,
??????????????? },
??????????????? "b": {"fontSize": 16, "lineHeight": 33},
??????????????? "per": {
?????????? ?????????"color": "#eee",
??????????????????? "backgroundColor": "#334455",
??????????????????? "padding": [2, 4],
??????????????????? "borderRadius": 2,
??????????????? },
??????????? },
??????? ),
??? )
??? .set_global_opts(legend_opts=opts.LegendOpts(pos_left="left", orient="vertical"))
??? .set_series_opts(
??????? tooltip_opts=opts.TooltipOpts(
??????????? trigger="item", formatter="{a} <br/>: {c} (n5n3t3z%)"
??????? )
??? )
??? .render("nested_pies.html")
)
圖6房屋總價(jià)分布圖
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.family']='KaiTi'
plt.figure(dpi=120)
provinces=['57萬(wàn)-357萬(wàn)', '357萬(wàn)-657萬(wàn)', '657萬(wàn)-957萬(wàn)', '957萬(wàn)-1257萬(wàn)', '1257萬(wàn)-1557萬(wàn)']
gdp=[1829,869,206,52,12]
plt.barh(provinces[::-1],gdp[::-1],height=0.5)
plt.title('房?jī)r(jià)分布')
plt.grid(axis='x',ls='--',alpha=0.4)
plt.xlim(0,2000)
for i,j in enumerate(gdp[::-1]):
??? plt.text(j+0.05,i,j,va='center')
plt.xlabel('數(shù)量(套)')
plt.ylabel('總價(jià)')
plt.savefig(r"E:\工作\碩士\學(xué)習(xí)\統(tǒng)計(jì)軟件python\matplotlib條形圖.jpg",format="png")
plt.show()
圖7 房屋面積與房屋總價(jià)的散點(diǎn)圖
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
data = pd.read_csv(r"E:\工作\碩士\學(xué)習(xí)\統(tǒng)計(jì)軟件python\期末作業(yè)\qxhsj.csv")
data.head()
sns.lmplot(x="x3", y="y1", data=data)
plt.xlabel('房屋面積(平方米)')
plt.ylabel('房屋總價(jià)')
plt.savefig(r"E:\工作\碩士\學(xué)習(xí)\統(tǒng)計(jì)軟件python\matplotlib.jpg", format="png")
圖8 關(guān)注度人數(shù)與房屋總價(jià)的散點(diǎn)圖
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
data = pd.read_csv(r"E:\工作\碩士\學(xué)習(xí)\統(tǒng)計(jì)軟件python\期末作業(yè)\qxhsj.csv")
data.head()
sns.lmplot(x="x8", y="y1", data=data)
plt.xlabel('關(guān)注度(人次)')
plt.ylabel('房屋總價(jià)(萬(wàn)元)')
plt.savefig(r"E:\工作\碩士\學(xué)習(xí)\統(tǒng)計(jì)軟件python\matplotlib.jpg", format="png")
需要數(shù)據(jù)集的家人們可以去百度網(wǎng)盤(pán)(永久有效)獲?。?/p>
鏈接:https://pan.baidu.com/s/16GeXC9_f6KI4lS2wQ-Z1VQ?pwd=2138
提取碼:2138?
更多優(yōu)質(zhì)內(nèi)容持續(xù)發(fā)布中,請(qǐng)移步主頁(yè)查看。
備注:明天更新兩種預(yù)測(cè)房?jī)r(jià)的算法,分別是支持向量機(jī)和隨機(jī)森林回歸預(yù)測(cè)。
若有問(wèn)題可郵箱聯(lián)系:1736732074@qq.com?
博主的WeChat:TCB1736732074
? ?點(diǎn)贊+關(guān)注,下次不迷路!
?
?
?
到了這里,關(guān)于對(duì)利用Python爬取到的房?jī)r(jià)信息做數(shù)據(jù)可視化(附完整代碼)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!