生活随笔
收集整理的這篇文章主要介紹了
阿里天池:Airbnb短租房数据集分析
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
阿里天池:Airbnb短租數據集分析 1.項目介紹 2.字段介紹 3.分析目的和思路 4.模塊導入與數據讀取 5.探索性分析
1.項目介紹
數據來源 :https://tianchi.aliyun.com/competition/entrance/231715/information Python版本 :3.7.1 Pycharm版本 :社區版2019.2 共享,通過讓渡閑置資源的使用權,在有限增加邊際成本的前提下,提高了資源利用效率。隨著信息的透明化,越來越多的共享發生在陌生人之間。短租,共享空間的一種模式,不論是否體驗過入住陌生人的家中,你都可以從短租的數據里挖掘有趣的信息。
2.字段介紹
(一)listings表 :數據為短租房源基礎信息,包括房源、房東、位置、類型、價格、評論數量和可租時間等等,具體如下。
屬性名含義 id 房間編號 name 房間名稱 host_id 房東編號 host_name 房東名稱 neighbourhood_group 所屬區域組 neighbourhood 行政區劃 latitude 緯度 longitude 經度 room_type 房間類型(整套、獨立房間、床位) minimum_nights 最少住幾晚 price 價格 number_of_reviews 評論數 last_review 上一次評論 reviews_per_month 平均每月評論數 calculated_host_listings_count 房間數 availability_36 一年內可租用天數
(二)reviews表 :數據為短租房源的評論信息,僅包括房源 listing_id和評論日期。
屬性名含義 listing_id 被評論的短租房 date 評論日期
3.分析目的和思路
(一)目的 :基于Airbnb 2019 年 4 月 17 日公開的北京地區數據,進行行政區劃和短租房類型的維度拆分,對短租房供給、需求等進行探索性分析。 (二)思路 :
4.模塊導入與數據讀取
(一)模塊導入
import pandas
as pd
import numpy
as np
import matplotlib
. pyplot
as plt
import seaborn
as sns
from pyecharts
. charts
import Geo
from pyecharts
import options
as opts
from pyecharts
. charts
import Bar
from pyecharts
. charts
import Line
from pyecharts
. globals import ChartType
from matplotlib
. pyplot
import MultipleLocator
(二)數據讀取
plt
. rc
( 'font' , family
= 'SimHei' , size
= '12' )
io
= 'D:/PythonProject/(天池)短租數據集分析/數據集-匯總版/listings.csv'
data
= pd
. read_csv
( io
)
listings_df
= pd
. DataFrame
( data
)
(三)DataFrame相關信息查看
print ( '記錄行數為:{}' . format ( len ( listings_df
) ) )
print ( listings_df
. count
( ) )
如下圖,發現有不少記錄缺失某些字段的值。 如下圖,發現neighbourhood列數據不統一。 因此,對DataFrame做如下一些調整。
listings_df
. drop
( 'neighbourhood_group' , axis
= 1 )
listings_df
[ 'neighbourhood' ] = listings_df
[ 'neighbourhood' ] . str . split
( '/' ) . str [ 0 ]
5.探索性分析
(一)整體分析
1.1、價格分布
listings_df
[ 'price' ] . hist
( bins
= 50 , rwidth
= 0.98 , alpha
= 0.8 )
plt
. show
( )
如下圖,發現短租房的價格大部分在6000元以下。 進一步,限定價格區間。
listings_df_2000
= listings_df
. loc
[ listings_df
[ 'price' ] < 2000 ]
listings_df_2000
[ 'price' ] . hist
( bins
= 20 , rwidth
= 0.98 , alpha
= 0.8 )
my_x_ticks
= np
. arange
( 0 , 2000 , 100 )
plt
. xticks
( my_x_ticks
)
plt
. show
( )
發現大部分房屋價格在100到700之間。因為Airbnb本來的品牌理念就是實現空閑房屋的共享使用,大部分提供的房屋都是普通型,價格過高的不會太多。 1.2、地理位置分布 繪制地圖的話,可以使用pyecharts庫。
listings_i_p
= pd
. DataFrame
( listings_df
, columns
= [ 'id' , 'price' ] )
print ( listings_i_p
. head
( ) )
data_pair
= [ ]
for i
in range ( len ( listings_df
) ) : data_pair
. append
( ( listings_i_p
. iloc
[ i
] [ 0 ] , int ( listings_i_p
. iloc
[ i
] [ 1 ] ) ) ) def get_geo ( ) : city
= '北京' geo
= Geo
( ) geo
. add_schema
( maptype
= city
, itemstyle_opts
= opts
. ItemStyleOpts
( color
= "#eeeeee" , border_color
= "#111" ) ) for i
in range ( len ( data_pair
) ) : geo
. add_coordinate
( listings_df
[ 'id' ] [ i
] , listings_df
[ 'longitude' ] [ i
] , listings_df
[ 'latitude' ] [ i
] ) geo
. add
( '' , data_pair
, type_
= ChartType
. EFFECT_SCATTER
, symbol_size
= 4 ) geo
. set_series_opts
( label_opts
= opts
. LabelOpts
( is_show
= False ) ) pieces
= [ { 'max' : 100 , 'label' : '100以下' , 'color' : '#00008B' } , { 'min' : 101 , 'max' : 300 , 'label' : '100-200' , 'color' : '#87CEEB' } , { 'min' : 301 , 'max' : 500 , 'label' : '201-300' , 'color' : '#9370DB' } , { 'min' : 501 , 'max' : 700 , 'label' : '301-400' , 'color' : '#D8BFD8' } , { 'min' : 701 , 'max' : 900 , 'label' : '401-500' , 'color' : '#EE82EE' } , { 'min' : 901 , 'max' : 1100 , 'label' : '501-600' , 'color' : '#FF00FF' } , { 'min' : 1101 , 'label' : '價格1101以上' , 'color' : '#FF0000' } ] geo
. set_global_opts
( visualmap_opts
= opts
. VisualMapOpts
( is_piecewise
= True , pieces
= pieces
) , title_opts
= opts
. TitleOpts
( title
= "北京各區域短租房分布圖" ) ) return geo
beijing_geo
= get_geo
( )
beijing_geo
. render
( '北京各個區域短租房分布圖.html' )
如下地理位置圖所示, 中心地區點的密集程度相對較大,所供給的房子較多,且價格集中在500以下。其中,以100-400元的居多。 昌平區,懷柔區,延慶縣等非中心片區高價房源占比較多,平價房源比較稀少。
(二)按區域劃分
neighbourhood_count
= listings_df
[ 'neighbourhood' ] . value_counts
( )
room_type_count
= listings_df
[ 'room_type' ] . value_counts
( )
2.1、各區域短租房的數量
listings_df_n_c
= listings_df
. groupby
( [ 'neighbourhood' ] ) [ 'id' ] . count
( )
bar1
= Bar
( )
bar1
. add_xaxis
( listings_df_n_c
. index
. tolist
( ) )
bar1
. add_yaxis
( '' , listings_df_n_c
. values
. tolist
( ) )
bar1
. set_global_opts
( title_opts
= opts
. TitleOpts
( title
= "北京各區域短租房的數量分布" ) , yaxis_opts
= opts
. AxisOpts
( name
= "數量" ) , xaxis_opts
= opts
. AxisOpts
( name
= "區域" , axislabel_opts
= opts
. LabelOpts
( font_size
= 10 , interval
= 0 ) ) , visualmap_opts
= opts
. VisualMapOpts
( is_show
= True , type_
= "color" , max_
= max ( listings_df_n_c
. values
. tolist
( ) ) , pos_left
= '-20' ) )
bar1
. set_series_opts
( markpoint_opts
= opts
. MarkPointOpts
( data
= [ opts
. MarkPointItem
( type_
= "max" , name
= "max" ) , opts
. MarkPointItem
( name
= "min" , type_
= "min" ) ] ) , markline_opts
= opts
. MarkLineOpts
( data
= [ opts
. MarkLineItem
( name
= "average" , type_
= "average" ) ] ) )
bar1
. render
( 'bar1.html' )
效果如下 2.2、各區域短租房數量占比
neighbourhood_label
= neighbourhood_count
. index
neighbourhood_c_max
= neighbourhood_count
. idxmax
( )
explode
= { }
for i
in neighbourhood_label
: if i
in neighbourhood_c_max
: explode
[ i
] = 0.03 else : explode
[ i
] = 0
plt
. figure
( figsize
= ( 8 , 10 ) , dpi
= 120 )
plt
. pie
( neighbourhood_count
, labels
= neighbourhood_label
, explode
= explode
. values
( ) , autopct
= '%.2f%%' , startangle
= 90 , counterclock
= False , colors
= sns
. color_palette
( 'hls' , n_colors
= 16 ) )
plt
. title
( '短租房分布區域占比圖' )
plt
. show
( )
占比排名前三的朝陽、東城、海淀區的房源合計約占整體的60%,其中,朝陽區占了總房源數的37%。 2.3、各區域的短租房的均價
listings_df_n_m
= round ( listings_df
. groupby
( [ 'neighbourhood' ] ) [ 'price' ] . mean
( ) , 2 )
bar2
= Bar
( )
bar2
. add_xaxis
( listings_df_n_m
. index
. tolist
( ) )
bar2
. add_yaxis
( '' , listings_df_n_m
. values
. tolist
( ) )
bar2
. set_global_opts
( title_opts
= opts
. TitleOpts
( title
= "北京各區域短租房的均價" ) , yaxis_opts
= opts
. AxisOpts
( name
= "均價" ) , xaxis_opts
= opts
. AxisOpts
( name
= "區域" , axislabel_opts
= opts
. LabelOpts
( font_size
= 10 , interval
= 0 ) ) , visualmap_opts
= opts
. VisualMapOpts
( is_show
= True , type_
= "color" , max_
= max ( listings_df_n_m
. values
. tolist
( ) ) , pos_left
= '-20' ) )
bar2
. set_series_opts
( markpoint_opts
= opts
. MarkPointOpts
( data
= [ opts
. MarkPointItem
( type_
= "max" , name
= "max" ) , opts
. MarkPointItem
( name
= "min" , type_
= "min" ) ] ) , markline_opts
= opts
. MarkLineOpts
( data
= [ opts
. MarkLineItem
( name
= "average" , type_
= "average" ) ] ) )
bar2
. render
( 'bar2.html' )
如下圖所示,均價排名前5的懷柔、延慶、昌平、平谷和密云區,均價在整體水平760.35以上,且這幾個區域均分布于北京的偏北部,不算是中心市區。其中,懷柔區的短租房均價約平均水平的2倍。另外,價格最便宜的是豐臺區,地理上處于北京的中心地帶。這也大致上驗證了1.2 中的結論。 2.4 / 2.5 各區域各類型短租房的數量/均價 這里在區域維度下,再進行不同房型的劃分。
listings_df_nr_c
= listings_df
. groupby
( [ 'neighbourhood' , 'room_type' ] ) . agg
( { 'id' : 'size' } )
listings_df_nr_m
= listings_df
. groupby
( [ 'neighbourhood' , 'room_type' ] ) . agg
( { 'price' : np
. mean
} )
listings_df_nr_c_r
= listings_df_nr_c
. unstack
( )
listings_df_nr_m_r
= listings_df_nr_m
. unstack
( )
plt
. subplot
( 211 )
plt
. plot
( listings_df_nr_c_r
)
plt
. legend
( loc
= 'best' , labels
= [ 'Entire home/apt' , 'Private room' , 'Shared room' ] )
plt
. title
( '各區域各類型短租房的數量' )
plt
. subplot
( 212 )
plt
. plot
( listings_df_nr_m_r
)
plt
. legend
( loc
= 'best' , labels
= [ 'Entire home/apt' , 'Private room' , 'Shared room' ] )
plt
. title
( '各區域各類型短租房的均價' )
plt
. tight_layout
( )
plt
. show
( )
如下圖所示,整體上來說,在數量上,整租房>獨享房>床位房。而在均價方面,差異則較大,其中,朝陽區的三種房型都是最多的,但是價格卻是相對低廉。根絕圖2.2,懷柔區(非中心區域)中房子的數量排整體的第九,但是整租房、獨享房和床位房的均價都位列前茅。
(三)按房型劃分
3.1 各類型的短租房數量占比
room_type_label
= room_type_count
. index
plt
. figure
( figsize
= ( 8 , 10 ) , dpi
= 120 )
plt
. pie
( room_type_count
, labels
= room_type_label
, explode
= [ 0.03 , 0.03 , 0.03 ] , autopct
= '%.2f%%' , startangle
= 90 , counterclock
= False , colors
= sns
. color_palette
( 'hls' , n_colors
= 16 ) )
plt
. title
( '短租房類型占比圖' )
plt
. show
( )
如下圖所示,整租房數量最多,約占整體60%;而床位房僅約占整體6%左右。看得出,Airbnb在房源供給上,更傾向于提供中高質量的整租房,而非相對廉價的床位房。 3.2 可租用天數 以20天作為一個區間間隔進行統計。 這里room_type_a_y的數據是另外進行統計的,就不在此贅述了。
room_type_a_x
= [ '[0, 25)' , '[25, 50)' , '[50, 75)' , '[75, 100)' , '[100, 125)' , '[125, 150)' , '[150, 175)' , '[175, 200)' , '[200, 225)' , '[225, 250)' , '[250, 275)' , '[275, 300)' , '[300, 325)' , '[325, 350)' , '[350, 365]' ]
room_type_a_y
= [ [ 1498 , 366 , 731 , 2254 , 387 , 257 , 1018 , 1424 , 80 , 137 , 219 , 240 , 328 , 1051 , 6965 ] , [ 1458 , 300 , 382 , 1654 , 92 , 150 , 474 , 937 , 34 , 90 , 209 , 143 , 161 , 437 , 3317 ] , [ 237 , 36 , 32 , 248 , 11 , 8 , 50 , 174 , 1 , 10 , 23 , 4 , 14 , 50 , 761 ]
]
room_type_a_bar
= pyec
. Bar
( )
room_type_a_bar
. add_xaxis
( room_type_a_x
)
room_type_a_bar
. add_yaxis
( 'Entire home/apt' , room_type_a_y
[ 0 ] , stack
= 'stack1' )
room_type_a_bar
. add_yaxis
( 'Private room' , room_type_a_y
[ 1 ] , stack
= 'stack1' )
room_type_a_bar
. add_yaxis
( 'Shared room' , room_type_a_y
[ 2 ] , stack
= 'stack1' )
room_type_a_bar
. set_series_opts
( label_opts
= opts
. LabelOpts
( is_show
= False ) , markline_opts
= opts
. MarkLineOpts
( data
= [ opts
. MarkLineItem
( name
= "average" , type_
= "average" ) ] ) )
room_type_a_bar
. set_global_opts
( title_opts
= opts
. TitleOpts
( title
= '可租用天數' , pos_left
= 'right' ) , yaxis_opts
= opts
. AxisOpts
( name
= "短租房數量" ) , xaxis_opts
= opts
. AxisOpts
( name
= "租房天數" , axislabel_opts
= opts
. LabelOpts
( font_size
= 10 , interval
= 0 ) ) )
room_type_a_bar
. render
( 'room_type_a_bar.html' )
如下圖,整體上來看,接近全年可租用的房子數量是最多的,第二多的是[75,100)天這個區間,第三多的是一個月以下的。且無論在哪個區間,整租房占的數量都是最多的,最少的是床位房。看得出來,無論是面對有短期旅途而租房或者有較長期逗留而租房的客戶,airbnb主打的還是整租房共享。 3.3 房源熱度分析(評論數) 1)月評論量的時間序列 這里使用了reviews.csv的數據。
io2
= 'D:/PythonProject/(天池)短租數據集分析/數據集-匯總版/reviews.csv'
reviews_df
= pd
. DataFrame
( pd
. read_csv
( io2
) )
reviews_df
[ 'date' ] = pd
. to_datetime
( reviews_df
[ 'date' ] )
reviews_df
[ 'date' ] = reviews_df
[ 'date' ] . values
. astype
( 'datetime64[M]' )
reviews_df_ym_r
= reviews_df
. groupby
( 'date' ) . count
( )
reviews_df_ym_r_subset
= reviews_df_ym_r
[ '2016-01' : ]
ax3
= reviews_df_ym_r_subset
. plot
( marker
= 'o' , alpha
= 0.8 , label
= '評論數' )
plt
. grid
( linestyle
= '-.' )
plt
. xlabel
( "時間" )
plt
. ylabel
( "評論數" )
plt
. show
( )
發現,月評論總數整體上呈現逐年上升的趨勢,但是在每年1~2月有下降的趨勢(由于春節原因?)。對于整體的上升,會不會是由于使用Airbnb的用戶越來越多?或者是Airbnb采用某些運營方式驅動用戶進行評論? 2)分區域查看評論熱度 基于北京各個區域短租房的月評論數,使用了箱型圖和分布散點圖進行可視化。
listings_df_n_rpm
= listings_df
[ [ 'neighbourhood' , 'reviews_per_month' ] ]
fig1
= plt
. figure
( figsize
= ( 10 , 10 ) )
ax
= sns
. stripplot
( x
= 'neighbourhood' , y
= 'reviews_per_month' , data
= listings_df_n_rpm
, jitter
= 0.1 , palette
= sns
. color_palette
( "plasma_r" , n_colors
= 16 ) , alpha
= 0.3 , size
= 6 )
sns
. boxplot
( x
= "neighbourhood" , y
= "reviews_per_month" , data
= listings_df_n_rpm
, whis
= np
. inf
, palette
= "Set3" , width
= 0.5 )
y_major_locator
= MultipleLocator
( 1.5 )
ax
. yaxis
. set_major_locator
( y_major_locator
)
plt
. xlabel
( '區域' , fontsize
= 10 )
plt
. ylabel
( '月評論數' , fontsize
= 10 )
plt
. show
( )
各個區域短租房的月評論數的中位數基本在[0.5,1.5]的范圍內,如果用戶是在租完房后才評論,評論數高能否說明租房次數高?在朝陽區、東城區、豐臺區和豐城區這些在市中心的房子中,有的月評論次數在20次左右,該區域房子數量多,價格相對便宜,可能是由于出租次數多或者用戶較活躍,后續我們可以對這些房子有針對性地分析,看看有什么指的借鑒的地方。 同理,可以基于房型的維度,查看月評論數。中位數方面,三者較為接近。但是極大值方面,整租房>獨享房>床位房。 2)評論內容分析 對中文評論的詞頻進行統計,我的這篇博客有較詳細的介紹,這里就不贅述了。
傳送門 :https://blog.csdn.net/lam_yx/article/details/107790023.
效果如下,發現 “干凈 ”、“整潔 ”、“方便 ”、“熱情 ”等詞語出現頻率居高。 另外,可以對中文評論內容進行情感分析,情感傾向值取值范圍在[0, 1],越接近1表示正面情緒;越接近0表示負面情緒。 在我的這篇博客有較詳細的介紹,這里就不贅述了:
傳送門 : https://blog.csdn.net/lam_yx/article/details/107847264 .
后續待完善
總結
以上是生活随笔 為你收集整理的阿里天池:Airbnb短租房数据集分析 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。