開始使用免費開始

平均建物大小

房仲業者想了解建物面積是否隨時間改變。

你將把 melb 資料集依 date 分組並計算建物面積的平均值。接著把分組後的 DataFrame 轉成 Bokeh 的 source 物件,並建立一個折線圖。

本練習屬於課程

使用 Bokeh 製作互動式資料視覺化

檢視課程

練習說明

  • datemelb 進行分組,並計算 "building_area" 的平均值。
  • 建立 fig,分別將 x 與 y 軸標記為 "Date""Building Size (Meters Squared)",並將 x 軸刻度設為日期時間格式。
  • 將線條圖元加入 fig,使用 source 視覺化 building_areadate 的關係。
  • 產生名為 "property_size_by_date.html" 的 HTML 檔。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Group by date and calculate average building size
prop_size = melb.____("____", as_index=False)["____"].____()
source = ColumnDataSource(data=prop_size)

# Create the figure
fig = figure(x_axis_label="____", y_axis_label="____", x_axis_type="____")

# Add line glyphs
fig.____(____)

# Generate the HTML file
____
show(fig)
編輯並執行程式碼